Hi all. I am writing a simple app which uses only one view controller and am attempting to create different storyboards for different device sizes (instead of constraining objects; I am not good at constraints).
I have searched for hours on how to implement this properly. What I have done is created a different storyboard for each device family, and in AppDelegate I am determining the screen height and then loading the storyboard for that screen height. However the different storyboards are not loading and I'm not sure why. Here is a snippet of that code in AppDelegate's didFinishLaunching function:
var screenHeight = UIScreen().bounds.height
var storyboard: UIStoryboard
storyboard = getStoryboard()
let vc = storyboard.instantiateViewController(withIdentifier: "Main")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
func getStoryboard() -> UIStoryboard {
var storyboard: UIStoryboard!
if screenHeight == 568.0 {
storyboard = UIStoryboard(name: "SE", bundle: nil)
}
else if screenHeight == 667.0 {
storyboard = UIStoryboard(name: "SE2", bundle: nil)
}
else if screenHeight == 736.0 {
storyboard = UIStoryboard(name: "8Plus", bundle: nil)
}
else if screenHeight == 812.0 {
storyboard = UIStoryboard(name: "11Pro", bundle: nil)
}
else if screenHeight == 896.0 {
storyboard = UIStoryboard(name: "11ProMax", bundle: nil)
}
else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
return storyboard
}
All the storyboards are in my main bundle. I don't understand why they are not instantiating. Please help ASAP
I have searched for hours on how to implement this properly. What I have done is created a different storyboard for each device family, and in AppDelegate I am determining the screen height and then loading the storyboard for that screen height. However the different storyboards are not loading and I'm not sure why. Here is a snippet of that code in AppDelegate's didFinishLaunching function:
var screenHeight = UIScreen().bounds.height
var storyboard: UIStoryboard
storyboard = getStoryboard()
let vc = storyboard.instantiateViewController(withIdentifier: "Main")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
func getStoryboard() -> UIStoryboard {
var storyboard: UIStoryboard!
if screenHeight == 568.0 {
storyboard = UIStoryboard(name: "SE", bundle: nil)
}
else if screenHeight == 667.0 {
storyboard = UIStoryboard(name: "SE2", bundle: nil)
}
else if screenHeight == 736.0 {
storyboard = UIStoryboard(name: "8Plus", bundle: nil)
}
else if screenHeight == 812.0 {
storyboard = UIStoryboard(name: "11Pro", bundle: nil)
}
else if screenHeight == 896.0 {
storyboard = UIStoryboard(name: "11ProMax", bundle: nil)
}
else {
storyboard = UIStoryboard(name: "Main", bundle: nil)
}
return storyboard
}
All the storyboards are in my main bundle. I don't understand why they are not instantiating. Please help ASAP