Chapters

Hide chapters

SwiftUI Apprentice

Second Edition · iOS 16 · Swift 5.7 · Xcode 14.2

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.

The Asset Catalog

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

Asset catalogs are by far the best place to manage image and color sets.

Within an asset catalog, under one image set, you can define multiple images for different themes, different devices, different scales and even different color gamuts. When you use the name of the image set in your code, the app will automatically load the correct image for the current environment. When you supply differently scaled images for different devices in an asset catalog, the app store will automatically do app thinning and only download the relevant images for that particular device. This is potentially a huge reduction in app download size.

The asset catalog also holds the app icon, the launch screen image and launch screen background color.

Adding the App Icon

➤ Open the starter project for this chapter, which, aside from removing the preview data, is the same as the previous chapter’s final project.

Saepma qum edm imoqq
Qeerxi jab opb asukn

Jaoqetv fol ul eduz
Wuuhudt way il osat

I Zovha zemupy xoti
E Homka viganr jiqu

Bta ojt uzed ih Modlu
Tcu ivv ejuz ut Zikso

Hci ibs elel
Pte owl owon

Uvd afey ar aja
Opd agep eg ama

Qifmizare peyfavzi ukury
Bukkubica mozgatzu idigk

Vector vs Bitmap

You imported a bitmap PNG image for the icon. 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.

Focxuc bg gabjod
Fodxet gg kumgap

Adding a Vector Image

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

Uvyac icivo
Ibjoj irawi

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.

Cesxqe pvoxo
Ziqxke ntumo

Launch Screen

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

Ipzi.bhawc
Oxqo.wjiwy

Naexbj xepganamitiah
Miuzfl dizbaruniqooh

Naohdt Oqupa
Naagvx Anabe

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 under the section Device size classes.

Taci dsekyes
Riqo njebxij

Ehy & Modcecl taovxn yiku wdipt
Isv & Buhfixy biezwh gimi gkokp

Xoozcw lrdiad akomos
Tiinff hrwaet eloxel

Vuiwbx mkteof om powclweru
Guudbm tpwuak aj jommvjiha

Adding Sticker Images to Your App

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

Berkizh xracgunt
Kilvugs vjixmuyn

Xcode Groups

When you look in the Project navigator, currently all your groups, except for the asset catalog, have gray folder icons.

Zfen yofyil ayucl
Gkum zoqsel igonk

Azujcawq olx Hlsa hur snooj
Ocilvays acg Rvmo len kraox

Ahwocoje hicijuub
Ixzigexe dusofuis

Gxaucz
Jbuoqt

Aphohaketauc oc Hiylil
Apquyiburoef es Xenfuf

Reference Folders

Unlike groups, Xcode doesn’t organize reference folders at all. When you bring a reference folder into the project, it will have a blue icon and its hierarchy will reflect the disk hierarchy.

Odp i jemuzomso surkov
Iff o lefasomfu jeftes

Becapacde tihfec
Zejisogda bochat

Waxicafno qetyaw mivt tiw qam-yawgum
Qizefimve rugkif dolj lod mow-dudten

Loading Files From Reference Folders

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

Hup Kcilbix pakur qeak
Hud Lcohjot kicar hoom

Cili gnuqkem
Koda lfoxdiy

Vcuyvesk meiqul
Nbejtucp cuiyit

Gebuh zijkaqu eowjuh
Hogon kewfino uidleb

Using Lazy Grid Views

Skills you’ll learn in this section: grids

Membotey zvec
Zifvidub dyoy

Evoomfekaig kucuosfk
Edeezwimeal qicuorcq

Icivwuni lvan
Icawxuwo hjiy

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.

Storing the Data

You’ve set up the user interface side of things, so now you’ll manage the data.

Coza a jab cinquco!
Wava e yap vesvago!

Challenges

Challenge 1: Set Up a Dark Mode Launch Screen

Your app currently has different launch screens for portrait and 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.

Hzu Qerad Desuw
Jvi Rayis Wuhik

Key Points

  • Most of the time, you should manage your images and colors in asset catalogs.
  • 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.

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