Reputation: 2059
Following the accepted answer to How to create an Empty Application in Xcode 6 without Storyboard I managed to have an empty application working in Xcode 8 (in Objective-C).
These are the steps that I took:
Main.storyboard
and its reference in info.plist
("Main storyboard file base name")LaunchScreen.storyboard
and its reference in info.plist
("Launch screen interface file base name")#import "ViewController.h"
Edited applicationDidFinishLaunchingWithOptions with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.rootViewController = [[ViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
If I follow these steps the screen of my app won't occupy the whole screen of the simulator, but only a portion. Following @tboyce12's comment to the accepted answer I made a second version, in which I didn't remove the LaunchScreen.storyboard file, so that the app finally occupied the whole screen of the simulator.
Is there a way of doing this programmatically?
Upvotes: 0
Views: 1213
Reputation: 115061
The launch screen (whether from a storyboard or static launch images) is displayed before your app begins executing; that is its purpose, to display something while the app is being launched.
As a result, you cannot provide the launch screen programatically.
The launch screen can either come from a storyboard, or you can provide launch images.
If you provide launch images, then you need to provide several images with appropriate dimensions for the various device types (iPad, iPhone 3.5", 4", 4.7", 5.5").
Originally, iPhones only had a 3.5" screen and many apps were hard-coded to the dimensions of this screen. When the iPhone 5 was released with a 4" screen there was a good chance that a number of existing apps would "break" because of their assumptions about screen size.
In order to provide backwards-compatibility for these apps, iOS checks to see if an app provides a 4" launch image (or uses a launch storyboard). If not, then the app is displayed in a 3.5" 'letterbox'. When you deleted your launch storyboard and didn't provide a 4" launch image, this is what you saw.
Since a launch storyboard can use autolayout to automatically adapt to the device screen size this is the preferred approach.
Upvotes: 2