2

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!

tomDev
  • 5,620
  • 5
  • 29
  • 39
  • 1
    This has turned into a duplicate of https://stackoverflow.com/questions/45404845/how-to-set-initial-storyboard – matt Nov 24 '17 at 19:44

2 Answers2

1

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
}
tomDev
  • 5,620
  • 5
  • 29
  • 39
0

Actually there is no need to do this if you well aware for Constraint concept , but you want to load different xib files than you can do it.

you have to put the condition for checking the device is iphoneX or not. you can compare the device based on its screen size. so i am not writing any hint for that.

if (iphoneX) {

  // initialized the Instance of ViewController with identifier(OR with NIB name) which is defined for iphoneX.

} else {

  // initialized the Instance of ViewController with identifier(OR with NIB name) which is Not defined for iphoneX.
}

Happy Coding.!

Er.Gopal Vasani
  • 448
  • 3
  • 12
  • Ok, but this doesn't answer the question. Where this should be placed, ondidFinishLaunchingWithOptions on appDelegate? How can I call a different storyboard? – tomDev Nov 24 '17 at 18:34
  • @tomDev , not in didFinishLaunchingWithOptions , when you want push your screen OR when you want initialize it. Yes but if this class is used as rootViewController Or one of the tabBarItem then you can use it within didFinishLaunchingWithOptions. – Er.Gopal Vasani Nov 27 '17 at 04:38
  • @tomDev , asnswer is very simple. – Er.Gopal Vasani Nov 27 '17 at 04:39