Search code examples
iosiphoneautolayoutstoryboard

Creating specific storyboard to iPhone X


I'm having a hard time to scale up everything to iPhone X using auto layout and constraints on a single storyboard.

iPhone 4s small screen, 6, 6+, all works well, but iPhone X tall screen with safe areas is a nightmare to custom design apps. It's just easier to create a specific storyboard only to the iPhone X, and keep the other storyboard to all other screen sizes.

As long as it's possible to do this. Can I load an specific storyboard only to iPhone X? How?

I already have an storyboard to iPad and another one to iPhone, but this can be configured on the plist.

Thanks!


Solution

  • I know this is not the best approach but it works flawlessly until I have time to make a universal storyboard.

    Add this to AppDelegate to split the storyboards between iPad, iPhone X, and other iPhones.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        let storyboard = grabStoryboard()
    
    }
    
    
    func grabStoryboard() -> UIStoryboard {
        // determine screen size
        let screenHeight = UIScreen.main.bounds.size.height
        let screenWidht = UIScreen.main.bounds.size.width
        var storyboard: UIStoryboard! = nil
    
        if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone) {
    
            if ( screenHeight == 812 && screenWidht == 375) {
    
                print ("iphone x") 
                storyboard = UIStoryboard(name: "Main_iPhoneX", bundle: nil)
    
            } else {
    
                print ("all other phones")
                storyboard = UIStoryboard(name: "Main", bundle: nil)
    
            }
    
        } else {
    
            storyboard = UIStoryboard(name: "Main_iPad", bundle: nil)
    
        }
    
        return storyboard
    }