Update: A Russian translation available at osxdev.ru here

iPhone 5 is out and it poses a new challenge to developers, a bigger screen. iOS developers have never been required to support multiple device resolutions in the past. But fret not, Apple has made things easy for us. Follow the four steps below and you are all set.

Step 1:

iPhone 5 requires a new instruction set, the armv7s. Only the latest Xcode, version 4.5 as on writing supports generating armv7s instruction set. Do note that, Xcode 4.5 no longer supports armv6 and deprecates iPhone 3G and older devices. So, build your app using Xcode 4.5

Step 2:

The next step is to add a launch image (Default-568h@2x.png). When you build your project with Xcode 4.5, you will see a warning, “Missing Retina 4 launch image”. Click “Add” to add a default image to your project.

Xcode 4.5 prompting for addition of a launch image for iPhone 5

Xcode 4.5 prompting for addition of a launch image for iPhone 5

 The app now launches in full screen on iPhone 5 without letter boxing on iPhone 5.

Step 3:

However, most of your nib files will still not scale properly. The next step is to check your auto resizing mask of every nib file and ensure that the view inside the nib file automatically sizes based on super view’s height.

Changing the auto resize mask

Changing the auto resize mask

The properties that you would use are UIViewAutoresizingFlexibleTopMargin, UIViewAutoresizingFlexibleBottomMargin, UIViewAutoresizingFlexibleHeight.
You use the UIViewAutoresizingFlexibleHeight for the top most view so that it autosizes with the main window. You use the UIViewAutoresizingFlexibleTopMargin and/or UIViewAutoresizingFlexibleBottomMargin for subviews.

The UIViewAutoresizingFlexibleTopMargin is used if you want the subview to be “pinned” to the bottom (top margin is flexible) and UIViewAutoresizingFlexibleBottomMargin is used if you want the subview to be “pinned” to the top (bottom margin is flexible).

When you use Cocoa Auto Layout, this step becomes optional. However, Auto Layout is not supported on iOS 5.

Step 4 (optional):

Lastly, any CALayer that you added to the view will have to be manually resized. The code below shows how to do this. I usually use a “patternLayer” to add a pattern to all of my view controllers. You should resize this in the viewWillLayoutSubviews method.

-(void)viewWillLayoutSubviews {
self.patternLayer.frame = self.view.bounds;
[super viewWillLayoutSubviews];

Step 5 (if you were a messy coder):

If you have hard coded the height of a view to 460 or 480, you might have to change them all using bounds. For example,

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

instead of

self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

That’s it. You are all set!


Follow me on Twitter