Skip to content

Commit

Permalink
change UI based on screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 10, 2020
1 parent 0311ec9 commit 89a6b39
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Binary file not shown.
10 changes: 8 additions & 2 deletions GHFollowers/Screens/SearchVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class SearchVC: UIViewController {
let logoImageView = UIImageView()
let userNameTextFiled = GFTextField()
let CTAButton = GFButton(backgroundColor: .systemGreen, title: "Get Followers")
// get access to the top constraint of the logo image so we can change its position based on the phone's screen size
var logoImageViewTopConstraint: NSLayoutConstraint!

// computed property to control if inout is empty
var isUsernameEntered: Bool {
Expand Down Expand Up @@ -81,11 +83,15 @@ class SearchVC: UIViewController {
func configureLogoImageView() {
view.addSubview(logoImageView)
logoImageView.translatesAutoresizingMaskIntoConstraints = false
logoImageView.image = UIImage(named: "gh-logo")!
logoImageView.image = UIImage(named: "gh-logo")

let topConstraintConstant: CGFloat = DeviceTypes.isiPhoneSE || DeviceTypes.isiPhone8Zoomed ? 20 : 80

logoImageViewTopConstraint = logoImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: topConstraintConstant)

NSLayoutConstraint.activate([
// place it on top after the safeArea and give it a margin of 80
logoImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 80),
logoImageViewTopConstraint,
// center the image in the view horizontally
logoImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
// set image height
Expand Down
41 changes: 35 additions & 6 deletions GHFollowers/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,41 @@
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import Foundation
import UIKit

enum SFSymbols {
static let location = "mappin.and.ellipse"
static let repos = "folder"
static let gists = "text.alignleft"
static let followers = "heart"
static let following = "person.2"
static let location = "mappin.and.ellipse"
static let repos = "folder"
static let gists = "text.alignleft"
static let followers = "heart"
static let following = "person.2"
}



enum ScreenSize {
static let width = UIScreen.main.bounds.size.width
static let height = UIScreen.main.bounds.size.height
static let maxLength = max(ScreenSize.width, ScreenSize.height)
static let minLength = min(ScreenSize.width, ScreenSize.height)
}


enum DeviceTypes {
static let idiom = UIDevice.current.userInterfaceIdiom
static let nativeScale = UIScreen.main.nativeScale
static let scale = UIScreen.main.scale

static let isiPhoneSE = idiom == .phone && ScreenSize.maxLength == 568.0
static let isiPhone8Standard = idiom == .phone && ScreenSize.maxLength == 667.0 && nativeScale == scale
static let isiPhone8Zoomed = idiom == .phone && ScreenSize.maxLength == 667.0 && nativeScale > scale
static let isiPhone8PlusStandard = idiom == .phone && ScreenSize.maxLength == 736.0
static let isiPhone8PlusZoomed = idiom == .phone && ScreenSize.maxLength == 736.0 && nativeScale < scale
static let isiPhoneX = idiom == .phone && ScreenSize.maxLength == 812.0
static let isiPhoneXsMaxAndXr = idiom == .phone && ScreenSize.maxLength == 896.0
static let isiPad = idiom == .pad && ScreenSize.maxLength >= 1024.0

static func isiPhoneXAspectRatio() -> Bool {
return isiPhoneX || isiPhoneXsMaxAndXr
}
}

0 comments on commit 89a6b39

Please sign in to comment.