ide ide - 6 months ago 108
iOS Question

Programmatically accessing the launch screen XIB or storyboard

How can an app access the XIB or storyboard used for its launch screen? The XIB is not in the main bundle (ex:

NSBundle.mainBundle().pathsForResourcesOfType(nil, inDirectory: "")
). This is especially unexpected since "Launch Screen.xib" is listed in the "Copy Bundle Resources" build phase but doesn't show ip in the bundle, so Xcode must be treating it specially.


As Xib is not in the main bundle getting path returns nil, But you can get the XIB of the launch screen without the help of path using method

  let launchScreenNib = UINib(nibName: "LaunchScreen", bundle: nil)


You can load get views from XIB as

// Swift
let objects = NSBundle.mainBundle().loadNibNamed("LaunchScreen", owner: self, options: nil)
let view = objects[0] as UIView

// Obj C
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil];
UIView *view = [objects objectAtIndex:0];