NEW: My free 100 Days of SwiftUI challenge starts tomorrow! >>

How to add Retina and Retina HD graphics to your project

Swift version: 5.0

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.

LEARN SWIFTUI FOR FREE I wrote a massive, free SwiftUI tutorial collection, and also have a growing list of free SwiftUI tutorials on YouTube – get started today!

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 Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift 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!