Consider switching between storyboards depending on the device.If you really want to switch between Xib files, replace the UIStoryboard
class in the code below with the UINib
class and read it.
I read the article on this blog.
Change your storyboard depending on your iOS device
First, create multiple storyboards.In the sample, we created two and named them Main
and iPhoneMain
, respectively.If you create a new Storyboard, you may want to replicate it to some extent because it starts with no objects at all.
Open the AppDelegate.swift
file and add the application(application:UIApplication, didFinishLaunchWithOptions launchOptions:)
method.
AppDelegate.swift
import UIKit
@UIAapplicationMain
classAppDelegate:UIResponder,UIApplicationDelegate{
var window —UIWindow?
func application(application:UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) ->Bool{
// Retrieving Devices
let device = UIDevice.currentDevice()
// Branch the name of the Storyboard by the model name of the device
varsbName="Main"
if device.model.hasPrefix("iPhone"){
// Determine if 4s or earlier by screen size
let screenSize = UISscreen.mainScreen().bounds.size
if screenSize.height<=480.0 {// 4s for height 480 pixels or less
sbName="iPhoneMain"
}
}
// Instance ViewController by calling Storyboard by name
let storyboard = UIStoryboard (name:sbName, bundle:nil)
iflet viewController=storyboard.instantiateInitialViewController(){
// Specify as rootViewController in the main window
self.window?.rootViewController=viewController
}
return true
}
hereinafter abbreviated
The UIDevice
class properties model
cannot distinguish between iPhone models, so we use screen size determination and matching techniques to determine if it is an iPhone 4s (previously).
Well, I think it's okay to judge only by the screen size.
© 2024 OneMinuteCode. All rights reserved.