티스토리 뷰

728x90
반응형

UIDevice 를 extension 으로 아이폰의 기종유무를 저장하는 변수를 만든다.

import UIKit

extension UIDevice {
    public var isiPhoneSE: Bool {
        if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone && (UIScreen.main.bounds.size.height == 568 && UIScreen.main.bounds.size.width == 320) {
            return true
        }
        return false
    }

    public var isiPhoneSE2: Bool {
        if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone && (UIScreen.main.bounds.size.height == 667 && UIScreen.main.bounds.size.width == 375) {
            return true
        }
        return false
    }

    public var isiPhone8Plus: Bool {
        if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone && (UIScreen.main.bounds.size.height == 736 || UIScreen.main.bounds.size.width == 414) {
            return true
        }
        return false
    }

    public var isiPhone12mini: Bool {
        if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone && (UIScreen.main.bounds.size.height == 812 && UIScreen.main.bounds.size.width == 375) {
            return true
        }
        return false
    }

    public var isiPone12Pro: Bool {
        if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad && (UIScreen.main.bounds.size.height == 844 && UIScreen.main.bounds.size.width == 390) {
            return true
        }
        return false
    }
}

view controller 에서 다음과 같이 기기대응을 할 수 있다.

// MARK: - UIComponents
    @IBOutlet weak var customNavigationBarViewHeight: NSLayoutConstraint!
    @IBOutlet weak var progressBarLeftAnchor: NSLayoutConstraint!
    @IBOutlet weak var indexLeftAnchor: NSLayoutConstraint!
    @IBOutlet weak var indexRightAnchor: NSLayoutConstraint!
    @IBOutlet weak var guideLabel1LeftAnchor: NSLayoutConstraint!
    @IBOutlet weak var guideLabel1BottomAnchor: NSLayoutConstraint!
    @IBOutlet weak var guideLabel1TopAnchor: NSLayoutConstraint!
    @IBOutlet weak var genderListCollectionViewTopAnchor: NSLayoutConstraint!
    @IBOutlet weak var genderListCollectionViewLeftAnchor: NSLayoutConstraint!
    @IBOutlet weak var genderListCollectionViewRightAnchor: NSLayoutConstraint!
    @IBOutlet weak var guideLable3TopAnchor: NSLayoutConstraint!
    @IBOutlet weak var nextButtonBottomAnchor: NSLayoutConstraint!
    @IBOutlet weak var genderListCollectionViewRatio: NSLayoutConstraint!

override func viewDidLoad() {
        super.viewDidLoad()

        setPhoneResolution()
    }

func setPhoneResolution(){
        if UIDevice.current.isiPhoneSE2 {
            customNavigationBarViewHeight.constant = 50

            progressBarLeftAnchor.constant = 16
            indexLeftAnchor.constant = 9
            indexRightAnchor.constant = 18

            guideLabel1TopAnchor.constant = 29
            guideLabel1LeftAnchor.constant = 16
            guideLabel1BottomAnchor.constant = 6

            genderListCollectionViewTopAnchor.constant = 15
            genderListCollectionViewLeftAnchor.constant = 11
            genderListCollectionViewRightAnchor.constant = 11

            guideLable3TopAnchor.constant = 31

            nextButtonBottomAnchor.constant = 28
        }
728x90
반응형
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
링크
Total
Today
Yesterday