iOS Dev: How to implement a Splash Screen (Default and Customized)?

This tutorial shows how to implement a splash screen on the start of an application. There are two ways to do so: A very simple standard way that shows the splash screen only four some millisecondes and another way in where you can determine the desired splashing time.

SDK Default:

This way is an already implemented feature in the SDK. All what you have to do, is to create a splash screen image named Default.png (name it exactly this way)  and put it in your Resources folder of your project. That’s it! On the next application start, the splash screen shortly appears before the root view is shown.

Indeed, it’s a very short splashing time and often app developers want to show up the splash screen for longer time. This case needs a custom implementation. Let’s do it!

Implementation with custom splash screen timer:

1) Create a new view controller. Let’s name it SplashViewController that inherites from UIViewController. You don’t need to implement anything in the interface and implementation class.

2) Create a new nib file. Let’s name it SplashView. Open it with the Interface Builder and add a ImageView to the view. Then, assign a image you want to have for the splash screen to the image view (Inspector -> Attributes -> Image View -> Image).

3) Now, let’s add some code to the app delegate interface class first, so it looks like the example below:

@class SplashViewController;

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
     UIWindow *window;
     UINavigationController *navigationController;
     SplashViewController *splashViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet SplashViewController *splashViewController;
@end

The only thing you have to do is to specify your splash view controller and add a property. Don’t forget to import SplashViewController by using @class.

4) Next, synthesize the splashViewController variable in your implementation class and extend the class by the following code:

-(void)applicationDidFinishLaunching:(UIApplication *)application {
     splashViewController = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
     [window addSubview:splashViewController.view];
     [window makeKeyAndVisible];
     [NSTimer scheduledTimerWithTimeInterval:1.5f target:self selector:@selector(onSlashScreenDone) userInfo:nil repeats:NO];
}

Initialize the splash view controller and add it as subview to the main window. Define your desired splash screen time with scheduledTimerWithTimeInterval:2.0f (2.0 is 2 seconds).
Further, add the following method to the class:

-(void)onSlashScreenDone{
     [splashViewController.view removeFromSuperview];
     [window addSubview:[navigationController view]];
     [window makeKeyAndVisible];
}

The method onSlashScreenDone is called when the timer was expired. It removes the splash view controller and adds the follow up controller as subview and make it visible (in our example, a navigation controller).

That’s it! Build your app and enjoy! 🙂

8 thoughts on “iOS Dev: How to implement a Splash Screen (Default and Customized)?

  1. I found a quick and dirty way to do this – I understand it’s not encouraged but works for small apps: sleep for 3 seconds under application did FinishLaunchingWithOptions like so:

    `- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    sleep(3);
    return YES;
    }`

  2. Thanks for that code snippet. I’ve currently read a Apple developer article that suggested not to use the sleep() function in the SDK 4 for non-concurrent operations. Apple actually doesn’t see a need for a splash screen at all. For that reason, they try to prevent exploiting the thread procedures for such cases.
    If you want to do it this way, you should rather use [NSThread sleepForTimeInterval:3.0] to ensure it works on all previous released and upcomming SDKs.

  3. Greetings from Florida! I’m bored to death at work so I decided to browse your site on my iphone during lunch break. I love the info you present here and can’t wait to take a look when I
    get home. I’m amazed at how fast your blog loaded on my phone .. I’m not even using WIFI, just 3G
    .. Anyways, great site!

  4. I just couldn’t go away your site prior to suggesting that I extremely loved the usual information a person supply on your visitors? Is going to be back steadily to investigate cross-check new posts

Leave a comment