Preparing your iPhone App for Higher Resolutions

Preparing your iPhone App for Higher Resolutions

Tutorial Details
  • Technology: iOS SDK
  • Difficulty: Beginner
  • Completion Time: 15 - 20 Minutes

With the iPad and the new iPhone 4 gaining popularity, it seems that iOS devices are quickly heading towards higher resolution displays. Higher resolution screens obviously make for a better user experience, but in order to take advantage of this, developers need to update their applications. This article will explain what all the fuss is about, and how to make your applications look good on higher resolutions by demonstrating two techniques for graphics optimizations.

Resolution, Screen Size and the Retina Display

The iPad has a bigger screen, and so it has a bigger resolution. With the iPhone 4, however, Apple did something different: they increased the resolution without changing the physical size of the screen. This makes for a higher pixel density, pixels are smaller and more tightly packed. In one square inch of the iPhone 4’s screen there are around 106 thousand pixels (at 326 PPI, or Pixels per Inch), while the older models have only about 26 thousand (at 163 PPI) in an inch – 4 times less! This makes graphics on the screen seem like continuous lines, because your eye can’t see the individual pixels. Apple calls this technology the “Retina Display” because they claim the human eye (the retina) can’t physically see the pixels at this resolution.

High resolution iPhone graphics

One of the great things about iPhone development, compared to other platforms, is that you know the precise size and resolution your application would be displayed on, so you can design and create to cater to those dimensions specifically. In order to keep that advantage as much as possible, Apple has doubled the resolution exactly – each pixel is replaced by 4 smaller pixels. This means that even if you choose not to take advantage of the Retina Display, your application will look the same as it does today.

On the iPad, where both the screen and the resolution are larger, Apple has allowed for “Pixel Doubling”, which blows up your applications to 4 times its size. In terms of pixels, your application after doubling is the same size as it would be on the Retina Display. This way you need to optimize your application only once, for double the resolution – on the iPad and the iPhone 4 (Unless, of course, you want to create a specific iPad version.)

What does this mean for my applications?

You have to hold an iPhone 4 in your hands to truly appreciate its screen and the importance of updating your application’s graphics. Optimized applications look noticeably better than the ones that aren’t, and updating isn’t as hard as you might think.

Already without doing a thing, any default Apple supplied Cocoa UI elements will render at a higher resolution on the iPhone 4. Text, Web Views and the like will also automatically update, so if you build your application entirely out of default UI elements you have no optimizations to make for the retina display! However, any pictures or image-based custom UI elements you might have in your application require some more work.

Generating higher-resolution graphics in Photoshop

The first step is to make a higher resolution version of each of your images. This will be demonstrated in Photoshop but the same principles can be applied in any graphics program.

Whenever you design an interface in Photoshop you should use non-destructive methods as much as possible. Creating your shapes with Vector graphics, using smart objects and layer styles instead of filters allows greater flexibility during the design process. When everything is editable, making small changes is easier, and creating higher resolution graphics becomes very simple.

As a demonstration, we will create a simple button and then make a high resolution version of it.

You should work on the main interface in the “old” resolution” of 320×480. This will allow you to have a better idea of what you are creating. Working from the beginning on the full 640×960 size might be confusing, because it looks huge on most monitors – and when viewing your design on the iPhone you might discover the buttons that seemed large in Photoshop are suddenly tiny. Most iOS devices are still 320×480, and you should target that resolution when designing.

Make a new document, at 320×480 and 163 ppi (iPhone 3G) and using the Shape Tool, draw a rounded rectangle. Make sure you’re creating a “Shape Layer” and not drawing a raster shape or a path. Style the rectangle to look like a button with Layer Styles such as Gradient Overlay, Stroke, Inner Glow and Drop Shadow to give it depth and form.

To make the large version, select Image Size from the Image menu and double the ppi to 326, iPhone 4 ppi. This will double our image size to 640×960. Make sure Scale Styles is checked and click OK. Make sure everything scaled up properly. You can add small details or subtle textures that will really make your application shine on the Retina Display. You now have a larger version of your UI, ready to slice and save.

Applying the Images

Now that we have our interface in Retina-resolution we need to apply it to our application. There are two ways to do that, each with pros and cons.

Using Two Images

The official way of adding high-resolution support to your application is by having two versions of each image, one in “regular” resolution and one in double resolution. Whenever your application is viewed on the Retina Display, the larger image will be loaded automatically. This method allows for full and precise control of how your application will look in each case, and is very easy to apply to your existing applications.

The full size image file should be named however you want, such as “Button.png”. Use this image name in your code and Interface Builder wherever you want to reference the image. The double-size image should be twice the size of its matching smaller image and named exactly the same with “@2x” appended to the name. In our example, we would name it “Button@2x.png”.

Unfortunately, this technique will not work on the iPad; a pixel-doubled application will not load the higher resolution resource. This will probably be addressed in the future iOS 4 update which is scheduled to come to iPad this fall.

Using Scaling

An alternative method to add high-resolution support is using scaling. You load only the large image resource, and then scale it to 50% in your code or using Interface Builder.

To do this using Interface Builder, create a new Round Rect Button (UIButton) and open the Attributes Inspector (Command-1.) Set the button type to “Custom” and select the large image as the Background. Write whatever you want in the Title attribute and style the button further if you want. In order to make our button the correct size, go to the Size tab and change the width and height of the button to half those of the image. The button image, for example, is 300×102, so the button will be 150×51. Because we are scaling by exactly 50%, even the simple scaling algorithm used by Cocoa Touch looks pretty good, given that our image is made of 2 pixel strokes and even-numbered pixel sizes, which are easy to divide by 2.

The result is as good as the specifically sized image when scaled, but this may vary depending on the image used. The same technique can be easily adapted to images and custom views for the same effect. Using this way will give you less control of how your application will look on a smaller screen, but it has a few advantages. The app bundle will contain one of each image instead of a smaller and larger copy. If your application has a lot of images, it might actually make a difference in file size. Furthermore, this is currently the only way to have high-resolution graphics on the iPad when pixel-doubling. Text and Apple UI elements will still be pixelated, but higher resolution images will improve the user experience until Apple adds official support for double-resolution on the iPad.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://alexeckermann.com/ Alex Eckermann

    Fantastic! Been wanting a good tut on app graphics over the different resolutions. Cheers.

  • http://interactivelogic.net/ Evan K. Stone | InteractiveLogic

    Good tips and good timing now that I and many others are considering the impact of iPhone 4′s Retina Display on our designs.

    Thanks!

  • http://ramblingwood.com Alec

    Good article, didn’t know it was so easy! I will do it right now!

    Also you have a small nitpicky spelling error: “…future iOS 4 update witch is scheduled…” should be “…future iOS 4 update which is scheduled…”

  • http://Designturd.tumblr.com Design Turd

    Hahah! nice post you could have just turned the ppi to 326 and bumped up the size by a third to make it fit for iphone 4 and ipad.

  • http://joelcolombo.com.ar Joel Colombo

    Just one question… in the resize dialogue box, don’t you have to change the 72 PPI and set it to 326 (and then double the actual size in pixels) in order to work with the same PPI relationship of the iPhone?

    Why you work at 72PPI there? Is there any difference?

    • Jon Shamir
      Author

      That’s actually a mistake, it should be 163 ppi (iPhone 3G ppi), though it doesn’t really make a difference in terms of image size because it isn’t going to be printed, though it’s always better to work at the correct ppi…
      When I think about it changing the ppi would be more elegant than changing the percentage (like Design Turd suggested I think), but it really doesn’t matter for the end result

      • Rafael John

        Hi, thanks! I got confused when you said it was supposed to be 163 ppi then change to 326 when upsizing, casue I’ve read on recent articles here that we should *or can* start at 72 ppi, *cause the ppi will just be dropped.
        But when I read your explanation, I see that its just a matter of preference on the ppi part, and I think we both agree that working on the correct ppi is more elegant. and I also prefer upsizing the ppi and not the percentage.

        Cheers!!

  • Sali

    Nice article. Saved my time!

  • eu4ria

    “The iPad has a bigger screen, and so it has a bigger resolution” having a bigger screen doesn’t automatically mean a device has a higher resolution.

    • Jon Shamir
      Author

      That is true, but in this case it does, and usually a bigger screen would have a higher resolution to take advantage of the size.
      I agree that this sentence isn’t phrased correctly anyway…

  • http://nfxdesign.com/ Laurence Orr

    Very good jumpstart on retina display. I am reworking an interface right now for the iPhone4. Thanks

    Laurence

  • Alice

    I’ve been confusing about resolution of retina. This articl is very clear.
    Thank you very much~ !

  • http://www.ovidovi.com Ivo

    Great tutorial! I wish I would have found it earlier in my design phase.

  • Divya

    Very informative article! Thank you for sharing.

  • http://www.alifewithoutprocrastination.com Bart

    Thank you for this tutorial. It is challenging for developers, but also so exciting to work with such a stunning screen as that of the iPhone 4 (and new iPod Touch). Great work!

  • http://www.twitter.com/AMyburgh Adrian

    Clearly explained and useful post! Big thanks.

  • Thomas Konrad

    Thanks so much! Great work there!

  • mardi

    I create all my artwork at the respective pixel dimensions using 72ppi. My images seem fine on the devices. Will they get sharper if I use 163 or 326 ppi, or does this only effect physically printing the images?

  • Bilal

    very much confusing about this topic………when i c those view then my confusion is vanish…………

  • Nick

    Hi there, great post by the way. Just a quick question though; I have been designing graphics for a number of iPhone applications and have been designing in Photoshop using images with 326ppi.
    However I have not resized the images for the iPhone 3′s resolution (163ppi) and the applications have worked fine on that device. Therefore is it necessary to prepare images in 163ppi as well 326ppi considering the application has worked fine on iPhone 3?

  • Nero

    Thank you for sharing. Nice article!

  • http://www.unetouchedhistoire.com CedricSoubrie

    Hello, I’m using a mix of both technic in my app but it seems that scale technic is really not working well for images that contains text. The text become crispy on 3GS for example.

    As it would save me a lot of space not to have two versions of my images, I’m looking for “scaling” options that would make the text looks nicer on 3GS. Do you have any idea ? Anti-aliasing or such things?

  • Michael L

    Just to clarify some of the confusing people are having about the PPI. The PPI has absolutely NO effect when designing for screen useage. It only has an impact when you are trying to print your images. PPI is only used for printing so all of the talk about what PPI/DPI you should use when you design for web, iPhone and any other digital screen is completely irrellevant.

    :)

  • http://www.capgunmedia.co Omar

    flipin phenomenal — I love this tutorial. It saved my life. I feel like Carly Rae Jepson when that guy with the ripped jeans actually called her!

    Y’all rock!