2

Execute Code in Launch Screen ORIGINAL

Now that the default LaunchScreen file in Xcode projects have been changed from .xib to .storyboard files (just like Main.storyboard), is it now possible to design the launch screen programmatically if you choose to?

Can you write custom code for the launch screen?

Community
  • 1
  • 1
Max Goodridge
  • 373
  • 2
  • 7
  • 21

3 Answers3

4

It is not possible to write any custom class/code for the launchscreen xib/storyboard files. We can only design using resource files.

Aruna Mudnoor
  • 4,795
  • 14
  • 16
2

Completely Agree with Arun Ammannaya. I ran a test to verify it and here is the result.

Can't add custom class to Launch Screen

Community
  • 1
  • 1
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
-2

Yes, its possible to write ViewController for the launch screen,

1) Create viewController file, create Xib for the same.

2) In the RootViewController's (say HomeViewController or SignInViewController) ViewDidLoad(),

2a) Create object of SplashViewController.

2b) Add view of splashViewController to your HomeViewController.

let objSplashVC = yourCode to create object of SplashVC
self.view.addSubView(objSplashVC.view);

c) After 2 or 3 seconds or once your retrieve data on Web-Service call, you can remove that view, by calling hide() method of SplashViewController

hide(){
       self.view.removeFromSuperView();
   }

Note : You have to add background image on SplashViewController as same as launchImage. So transitions will go smoothly.

Hitendra Solanki
  • 4,871
  • 2
  • 22
  • 29
  • 2
    This is not what the question is asking for. This presents a splash view controller after the app is launched and the launch screen has been shown. The OP wants the launch screen done with code. – rmaddy Jan 07 '16 at 15:18
  • @rmaddy Yes I agree, although it is a sneaky workaround and may be useful in specific app designs - it isn't really an answer to my question. – Max Goodridge Jan 07 '16 at 20:30