简体   繁体   中英

How to fit iPhone app for iPad app in iOS Swift 3.1 Xcode 8.3.2

I made iOS application with swift 3 and Xcode 8.3.2 and it's works correctly(Fit to All of iPhone screen size) but in iPad has problem for fit.
I set iPhone mode in General/Target setting.
Already i did this process and there is no problem.
Please help me to fix it.And i don't wanna to set setting Universal.
See this:
在此处输入图像描述

you can set a different storyboard for iPad and iPhone from you info.plist or you can load your specific storyboard from your appdelegate. you can check this link out

well you can change the screen size or component constraint value by using this below code by using it in your class so, you can set your view for iphone and ipad.

    struct Device {
    // iDevice detection code
    static let IS_IPAD             = UIDevice.current.userInterfaceIdiom == .pad
    static let IS_IPHONE           = UIDevice.current.userInterfaceIdiom == .phone
    static let IS_RETINA           = UIScreen.main.scale >= 2.0
    static let SCREEN_WIDTH        = Int(UIScreen.main.bounds.size.width)
    static let SCREEN_HEIGHT       = Int(UIScreen.main.bounds.size.height)
    static let SCREEN_MAX_LENGTH   = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) )
    static let SCREEN_MIN_LENGTH   = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) )
    static let IS_IPHONE_4_OR_LESS = IS_IPHONE && SCREEN_MAX_LENGTH  < 568
    static let IS_IPHONE_5         = IS_IPHONE && SCREEN_MAX_LENGTH == 568
    static let IS_IPHONE_6         = IS_IPHONE && SCREEN_MAX_LENGTH == 667
    static let IS_IPHONE_6P        = IS_IPHONE && SCREEN_MAX_LENGTH == 736
    static let IS_IPHONE_X         = IS_IPHONE && SCREEN_MAX_LENGTH == 812
    }

now you can set constrain like this:==

    if(Device.IS_IPHONE_5 || Device.IS_IPHONE_4_OR_LESS){
        //--- set your constrain for iphone 5 and 4
    }else if(Device.IS_IPAD){
        //--- set your constrain for ipad
    }else{
        //--- set default constrain
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM