TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

How to add Retina and Retina HD graphics to your project

Swift version: 5.10

Paul Hudson    @twostraws   

iOS has a simple, beautiful solution for handling Retina and Retina HD graphics, and in fact it does almost all the work for you – all you have to do is name your assets correctly.

Imagine you have an image called taylor.png, which is 100x100 pixels in size. That will look great on non-Retina devices, which means iPad 2 and the first-generation iPad Mini. If you want it to look great on Retina devices (which means iPad 3, 4, Air, Air 2, Mini 2, Mini 3, Pro, plus iPhone 4s, 5, 5s, 6, and 6s) you need to provide a second image called taylor@2x.png that is 200x200 pixels in size – i.e., exactly twice the width and height.

Retina HD devices – that’s the iPhone 6 Plus, iPhone 7 Plus, and iPhone 8 Plus – have an even higher resolution, so if you want your image to look great there you should provide a third image called taylor@3x.png that is 300x300 pixels in size – i.e., exactly three times the width and height of the original.

If you're not using an asset catalog, you can just drag these images into your project to have iOS use them. If you are using an asset catalog, drag them into your asset catalog and you should see Xcode correctly assign them to 1x, 2x and 3x boxes for the image. It's critical you name the files correctly because that's what iOS uses to load the correct resolution.

With that done, you just need to load taylor.png in your app, and iOS will automatically load the correct version of it depending on the user's device.

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Available from iOS 8.0

Similar solutions…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 5.0/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.