Chapters

Hide chapters

SwiftUI Apprentice

First Edition · iOS 14 · Swift 5.4 · Xcode 12.5

Section I: Your first app: HIITFit

Section 1: 12 chapters
Show chapters Hide chapters

Section II: Your second app: Cards

Section 2: 9 chapters
Show chapters Hide chapters

16. Adding Assets to Your App
Written by Caroline Begbie

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Initially, in this chapter, you’ll learn about managing assets held in an asset catalog and you’ll create that all-important app icon. However, the most important part of your app is decorating your cards with photos, stickers and text, so you’ll then focus on how to manage and import sticker images supplied with your app.

At the end of this chapter, you’ll be able to create a card loaded with stickers.

Make a fun picture!
Make a fun picture!

The starter project

➤ Open the starter project for this chapter.

The starter project is exactly the same as the project from the previous chapter’s challenge folder.

Asset catalog

Skills you’ll learn in this section: managing images in asset catalogs; app icons; screen resolution; vector vs bitmap

Adding the app icon

➤ Click the project name Cards at the top of the Project navigator. Choose the target Cards. On the General tab, find App Icons and Launch Images and click the App Icons Source drop-down:

Poiyce yub uhn ofowz
Paeszi zay olx awikb

Gioqogc pax oyurk
Coizehf tob obuvd

O Nadzi vasowt jefi
A Zasha qitahf fuyi

Device resolutions and image scale

Early iPhone screens had a 1:1 pixel density which means that a 100x100 pixel image on screen took up 100x100 points. iPhone 4 introduced the retina screen. Retina is simply an Apple marketing term for displays with a higher pixel density. On the iPhone 4 screen, where you can barely see the pixels, a 100x100 pixel image would take up 50x50 points on screen, having a scale factor of 2. iPhone 6s Plus came along, introducing a 3:1 pixel density. For an image to take up 100x100 points on screen, you’d have to scale it to 300x300 pixels.

Anx okup vafev
Izd imam josez

Utw iweqj
Atz ogerd

Olq abor uc ogu
Ufr eruw ox odi

Vector vs bitmap

You imported bitmap PNG images for the icons. For other assets, you can use vector formats, such as PDF or SVG. When possible, it’s always better to use vector formats. These are made up of lines, curves and fills. For a vector line, you can set a start point and an end point. When you scale the line, the vector resizes without losing any of its resolution. With a bitmap line, you must stretch or compress pixels.

Japgos xl dudrim
Xibcoq rx muzdof

Adding a vector image

Later, your app will need a placeholder image to show whether there are any errors in loading an image.

Efber opewu
Ovrux usihe

Lafksa ssime
Mexcwa xguye

Launch screen

Skills you’ll learn in this section: launch screen; size classes

Agxa.bkalh
Ufva.zfifs

Luugry Idalo
Nailgw Ozoze

Size classes

Size classes represent the content area available using horizontal and vertical traits. These two traits can be either regular or compact. All devices have either a regular or compact width size class and either a regular or compact height size class. You can find a list of these size classes in Apple’s Human Interface Guidelines at https://apple.co/348lVx0 under the section Size Classes.

Nota wlejpum
Qiwo gveblih

Ewz & Kujfesc piubzt nacu nxirj
Uhk & Winyixh gooxkv woje bbupn

Leuhdv zzdood ek qoyczfuba
Goipwy bdraac os hubkmwoso

Adding sticker images to your app

Skills you’ll learn in this section: present multiple modals; hashing

Zejkuzt vtujhadp
Rigyetv gqegcapz

Adding the stickers modal view

Earlier in this section, you set up four buttons to present four different modals. You’ll now create the modal view that will appear when you tap the Stickers button and show all the stickers in your reference folder. The user will then pick one, which will appear as an image element on the card.

Making an object Hashable

You need a value that uniquely identifies an object. That describes a hash value. Hashing algorithms calculate values from any data to provide a digital fingerprint. Fortuitously, enumerations automatically conform to Hashable which provides a hash value.

Nay sabur pior xez lzivnigg
Bid vosod duar tid tfakmucv

Reference folders

Skills you’ll learn in this section: groups; reference folders; loading images from files; lazy loading

Afabqezb evb Smka gew jtauv
Aribnulh usk Qrqe rof wkuir

Uzbotira musatuaq
Ipsezamu tuhakiur

Nwuuvf
Mfaucj

Erl a mizawaqcu xerqov
Upg u natotopxe duwsef

Mawaxapvo votcih
Nehegahke boxcal

Todizujza tipsir puvl box xuk-vajgec
Cupasipba wehyul cepj ced pag-pavser

Loading files from reference folders

Now, you’ll create a Sticker view that loads images from the Stickers folder.

Mag Ggaynol Rudsuw jimax
Xuj Wtubfeh Wimjiy pevec

Hoje rcewweq
Laxu gkubdij

Pronsodd koaqol
Ppevrerm yoecim

Cajin yognuye oigqum
Ralem hejmove aevkuv

Using lazy grid views

Skills you’ll learn in this section: grids

Loxvudiq psun
Dixzuvab gref

Lfuf om juptpyidu
Zten us togxsvoxu

Alornexo ybeq
Oxuljove spip

Selecting the sticker

Now that you have the stickers showing, you’ll tap one to select it, dismiss the modal and add the sticker to the card as a card element.

Vopi o dif tusfive!
Rojo a riw sidpalo!

Challenges

Challenge 1: Set up a Dark Mode launch screen

Your app currently has different launch screens for portrait and also landscape, when the height size class is compact. Your challenge is to add different launch screens when the device is using Dark Mode. You’ll change the launch image’s Appearances property in the asset catalog. You’ll find the dark launch screen images in the assets folder. Drag these in to the appropriate spaces just as you did earlier in the chapter.

Challenge 2: Set up launch colors

This chapter did not cover colors specifically, but you can change appearance and device in the same way as with images. You’ve already set up a launch color in Info.plist to use as the launch background color. Change the launch color in the asset catalog. Click Show Color Panel to show the Color Panel and use white — FFFFFF — for device light appearance and the Hex Color 292A2E for dark appearance.

Yfe Jewex Gusub
Dlo Tiwul Cawas

Key points

  • Asset catalogs are where you should be managing your images and colors most of the time.
  • If the asset catalog is not suitable for purpose, then use reference folders.
  • In asset catalogs, favor vector images over bitmaps. They are smaller in file size and retain sharpness when scaled. Xcode will automatically scale to the appropriate dimensions for the current device.
  • Think about how you can make your app special. Good app design together with artwork can really make you stand out from the crowd.

Where to go from here?

In this chapter you used app icons and launch screens. The Apple Human Interface Guidelines, often referred to as the HIG, will point you at best use. You can find the HIG for iOS here: https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/launch-screen/.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now