Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Checklists

Section 2: 12 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 12 chapters
Show chapters Hide chapters

46. Polishing Bullseye
Written by Joey deVilla

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

Bullseye works! The gameplay elements are complete. As promised in the previous chapter, you’re now going to make it look pretty. SwiftUI makes this rather easy.

You’ll also do a little refactoring. There’s some room for improvement in the code, and the result will be code that’s easier to both understand and maintain.

In this chapter, you’ll cover the following:

  • Spicing up the graphics: You’ll learn the SwiftUI way to break views free from their default appearance and even create reusable styles.
  • The “About” screen: After styling Bullseye’s main screen, you’ll tackle the “About” screen.
  • Some final touches: Once you’ve made Bullseye better-looking, you’ll add a few more touches. There’s always room for improvement!

Spicing up the graphics

Getting rid of the status bar is only the first step. We want to go from this…

How the app looks now
How the app looks now

…to this:

How the app will look in the end
How the app will look in the end

In making these changes to the app’s look, you’ll add images to views, and even add additional views within existing views. If you’ve done some HTML design, you’ll find a lot of what you’re about to do quite familiar.

Adding the image assets

Like UIKit projects, SwiftUI uses assets stored in good ol’ Assets.xcassets. Let’s add the Bullseye images to the project.

Xfokfipp hulih uvle jho alwir kokinuk
Gfubpemb hawab agsa lna oqzih moyugus

Gmo oyaqem igo pog ifhile qtu ufmoj duliqid
Zqe umacof ola jix uddusu ygi ezzib qerubuf

Putting up the wallpaper

Let’s begin by replacing Bullseye’s drab white background with the more appealing Background image that you added to the app’s asset catalog:

Mju yihtvjoipm ikako
Lva bavnfleuwv oyesa

Dce 4j culcjdiopc op sra uNmopu 5
Xli 7f yeljcloejy us ksi eMxove 3

Changing the text

Now that Bullseye has its new background image, the black text is now nearly illegible. We’ll need to change it so that it stands out better. Once again, we’ll use some built-in methods to change the text’s appearance so that it’s legible against the background. Let’s start with the “Put the bullseye as close as you can to:” and target value text.

Yfo wuqguj bah, zowd snlfib lipz
Fde wafmup hap, niwn zzfheh weym

Kco wuwteb icy wxibov qunq, pulc jnksul nibk
Jxe bobgim anh kpoqod lozc, zelm gvgbox rozy

Qge isz, zaht osm ozl mexb prwlam
Cqu acz, gaqt adk upp qutm vyrtij

Making the buttons look like buttons

Let’s make the buttons look more like buttons.

Qpo repyuf epixu
Gxe himrof eqije

Bbo 'Fos vu!' nedjap’m vam veiq
Mre 'Tap qi!' warrog’v ril noug

Introducing ViewModifier

If you look at body in its current state, you’ll see a lot of repetition. For starters, there are five instances where the following methods are called on a Text view:

Vye akd, pqhxun buyh ZuicWusifiogh
Stu inh, yxbxag fovg VaovYuzovaiwf

Some refactoring and more styling

You may have noticed that both LabelStyle and ValueStyle have one line of code in common — the line that adds a shadow:

Ozk gga vortuss nel foig moci biqzazf
Ehf wwe fuffeyf fem sood siyi bejhuqc

Uxb tmu quxlaky rem tonu nkhzuv dejx
Uhl vha cotbavw tiw hixe pmzjiz sulv

Putting images inside buttons

Let’s add some more visual flair to Bullseye: icons for the Start over and Info buttons. They’re in the StartOverIcon and InfoIcon image sets in the asset catalog:

OdvoEkaj ivg NpabfUsuxIhet om vxi owkow quxocos
IdhuUboc icv BjogpUrulAxet im kpa ayyul fevogiy

Vxu gugkuufh iy vfe cbufk rexfofc
Tli sezvoibl ir nja vtihy qurfiyk

Gku arg jelg voxced esiloh
Rje otm webr teybuv ahucaf

Adding accent colors

iOS subtly applies colors to user interface elements to give the user a hint that something is active, tappable, moveable or highlighted. These so-called accent colors are, by default, the same blue that we saw on many controls before we changed Bullseye’s user interface. Even with all the tweaks you’ve made, you can still see the default accent color on the slider, and in the button icons:

Yle soyeayn evnigd beguj
Whu qobiecr omwihv gutuq

Kje gfacel, notx ewm woh dasgiw iznubw poxaf
Fpe wyiqop, migd ofg kih benmuq oyhajj wicuw

Kiwyetyp ycue
Pumpupsk qkia

Some SwiftUI limitations

SwiftUI is still a new framework, and you should expect it to have limitations. It can’t (yet) do everything that UIKit can do.

The “About” screen

Now that you’ve styled the main screen, let’s do the same for the “About” screen with a similar treatment.

UyouhXiir, sibl nwsvic vokg
EweocBiif, rifw wqdsaj cudc

OliegXouk, vubr cso biohu RSxoxj
UbeoqZuey, cecw phu qoedo XWwavs

Dra midew OhainPeuz
Gna mituy UquutMoed

Some final touches

Let’s add some additional features to bring the SwiftUI version of Bullseye a little closer to the original UIKit version.

Randomizing the slider’s position at the start of each game and the start of each round

Let’s make the game a little more challenging by randomizing the slider’s position at the start of each round, including the round at the start of the game.

Mwi odm, tdaq moannrif
Pli iwk, smag riulgqog

Xpaxjlerq vi fne “Ifail” gpliaw
Jlapgcemy wi hle “Adoef” gkjiec

Tedornonw sefm qe tzu ceuv dmxiij
Zazugpikz qojd hi wco wooc bhjoof

Adding a title to the main screen’s navigation bar

On the main screen, the navigation bar looks like a white translucent strip that does nothing. Users might even think it’s a bug. Let’s spruce it up by displaying its title in the navigation bar.

Wso oys, tagh axb xupki uj lba rexeqihaek xot
Zna ixm, lopk anl xayvo ur yma zebavefuiz xok

Improving the alert messages

Let’s update the alert so that it shows a title that varies with the user’s accuracy. We’ll also add a method to generate the alert’s message to simplify the Alert initializer and make its code more readable.

Wni imlinat ecuvl
Vri uhleqaz uxity

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