I am using Xcode7 and Swift with Storyboards. When I open the LaunchScreen.storyboard, and I try to set a Custom Class on it, Xcode complains that one cannot have a custom c
No, The launch screen is shown before your app starts executing in order to provide a transition from the Springboard to your app while it is loading.
You can either use a fixed image or you can use a simple storyboard scene using only standard, static UI elements - labels & images.
This storyboard scene is actually loaded and displayed by the OS, so it would be a security risk to allow your code to execute in that context.
It works successfully
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
imageArr = ["1.jpeg","2.jpeg","3.jpeg","4.jpeg"]
let RandomNumber = Int(arc4random_uniform(UInt32(self.imageArr.count)))
//imageArr is array of images
let image = UIImage.init(named: "\(imageArr[RandomNumber])")
let imageView = UIImageView.init(image: image)
imageView.frame = UIScreen.main.bounds
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController()
window?.rootViewController?.view.addSubview(imageView)
window?.rootViewController?.view.bringSubview(toFront: imageView)
window?.makeKeyAndVisible()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
}
return true
}