Reputation: 303
I want to separate my design for iPad and iPhone, so is it possible to use 2 different design with one ViewController functionality. Or if you have any other solution then you can help me.
I want to separate my design for iPad and iPhone
Upvotes: 0
Views: 209
Reputation: 107121
Yes, you can do that. You can add multiple storyboard designs for the same view controller class. You can do the following in iOS 13, which will specify which storyboard to use for iPhone and iPad:
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
let config = UISceneConfiguration(name: "Default Configuration", sessionRole: .windowApplication)
config.sceneClass = UIWindowScene.self
config.delegateClass = SceneDelegate.self
if UIDevice.current.userInterfaceIdiom == .phone {
config.storyboard = UIStoryboard(name: "Main", bundle: nil)
} else {
config.storyboard = UIStoryboard(name: "Main_ipad", bundle: nil)
}
return config
}
Reference: Separate Storyboard for iPhone and iPad With Multiple Windows
If you want to move to a different storyboard view from the Main storyboard in the above scenario, either you can use a storyboard reference or use the following code:
let storyboard = UIStoryboard(name: "your-ipad/iphone-storyboard", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "yourVCIdentifier")
Upvotes: 3