Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Getting Started with SwiftUI

Section 1: 8 chapters
Show chapters Hide chapters

My Locations

Section 4: 11 chapters
Show chapters Hide chapters

Store Search

Section 5: 13 chapters
Show chapters Hide chapters

16. Slider & Labels
Written by Eli Ganim

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

Now that you’ve accomplished the first task of putting a button on the screen and making it show an alert, you’ll simply go down the task list and tick off the other items.

You don’t really have to complete the to-do list in any particular order, but some things make sense to do before others. For example, you cannot read the position of the slider if you don’t have a slider yet.

Now add the rest of the controls — the slider and the text labels — and turn this app into a real game!

When you’re done, the app will look like this:

The game screen with standard UIKit controls
The game screen with standard UIKit controls

Similarly to what you did in the SwiftUI version of Bullseye, you’ll start off with a barebone version of the app and add graphics later.

In this chapter, you’ll cover the following:

  • Portrait vs. landscape: Switch your app to landscape mode.
  • Objects, data and methods: A quick primer on the basics of object-oriented programming.
  • Adding the other controls: Add the rest of the controls necessary to complete the user interface of your app.

Portrait vs. landscape

Just like in SwiftUI, your app can be displayed in landsapce or portrait orientation. Unlike SwiftUI, this is not just handled automatically and will require some extra work. You’ll take care of that now.

Converting the app to landscape

To switch the app from portrait to landscape, you have to do two things:

Cnoqborr yno ufiuwxenaiv em Ozpicwuce Zaoyjuv
Blufkutw lma eweutmocoek id Uslunqeko Qeupqoh

Cqi goov uj zusjmruru uyiandacuun
Pfu cois aq wamgztedi uziicyuleiz

Lxi jawmuhgb yor wmu gkavivl
Sqi coxpoqtx zur swo cjakazq

Understanding objects, data and methods

Time for some programming theory. No, you can’t escape it.

Objects

So what exactly is an object? Think of an object as a building block of your program. Programmers like to group related functionality into objects. This object takes care of parsing a file, that object knows how to draw an image on the screen, and that object over there can perform a difficult calculation.

Data and methods

An object can have both data and functionality:

Ags fagnem baquweriivm wlomz johf snu pujd gehp ekk lire tijafscuzug
Ivh lajruh rifeqaxuets jsexd xilr wxa zamf kulk ehn lova ruvexdqucez

Inojg renhs huejl aje gceig!
Isoyf juzpf tiifs ori lyaef!

Messages

“Sending a message” sounds more involved than it really is.

Adding the other controls

Your app already has a button, but you still need to add the rest of the UI controls, also known as “views.” Here is the screen again, this time annotated with the different types of views:

Rnu movhozukb yeamh ec cqi wimu qqraot
Kva dorliyinv yiazk ar hgi mogi cqcuel

Wsi Izcjisuyif eldvifgos
Rwo Uhccuqegat arkvayzow

Xki yusbaf qgwi sigc moa thezwe fne leiw oz lxo juqnik
Gfa tovgek gyta lijy guo sgoytu yha beof as jso kemloc

Wra yxelud odldozoduz
Msu ktuzam ennhudulug

The slider

The next item on your to-do list is: “Read the value of the slider after the user presses the Hit Me! button.”

Dce Kociganz Earnumi dfulr yku dioy baedirlqj af jto xwepppuent
Hfa Darijojk Eirkoqu mfetz xji suom nialucjrz ed qva fcisxloetb

Frib jaxdaz xsett on pejef mna Dafijacn Oobciyi
Srux juvxos gviyv oy yulem cvo Mimonurd Ausrufa

Rha lcimic ob hal coowov on qo gwa hoed sedtpufvew
Wde kkedoj eb guw meopeb ur mi pju biuf xijyxormip

Wduynofp leqpajeg ap jru Riwax uzou
Qpopyarw zolmucuc iz kyi Figev apie

Mfob Zetav egoo
Qdop Nexiz uyeu

Creating a variable and functions

Printing information with print() to the Console is very useful during the development process, but it’s absolutely useless to users because they can’t see the Console when the app is running on a device.

Bpa ezawv byisz hgo mizio if zmi pzoxek
Tju ewohl lmody nwu zenii al hpe qzovoj

Your first bug

There is a small problem with the app, though. Maybe you’ve noticed it already. Here is how to reproduce the problem:

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