d0tb0t
d0tb0t

Reputation: 303

Can I use different Storyboard Design for same ViewController

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

Answers (1)

Midhun MP
Midhun MP

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

Related Questions