Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift By Example

You're reading from   Swift By Example

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781785284700
Length 284 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Giordano Scalzo Giordano Scalzo
Author Profile Icon Giordano Scalzo
Giordano Scalzo
Arrow right icon
View More author details
Toc

The menu screen

Let's start implementing the first view, in which we can select the level of the game.

Implementing the basic menu screen

As we have planned to implement all of the UI in the code itself, we won't bother to touch the storyboard. We will proceed to open the ViewController class to implement the menu screen.

Looking at the mockup, we can see that we have three levels of difficulty: easy, medium, and hard. There are three buttons, each one used to select one of them. Also, the buttons are horizontally centered and vertically equidistant.

First of all, we define an enumeration to describe the difficulty.

Then, we implement the setup for the layout:

enum Difficulty {
    case Easy, Medium, Hard
}

Just for the sake of readability, we group the methods needed to implement a feature in a separated extension, leaving in the main class only the public functions and the variable definition. Although extensions were born for a different goal, which is to extend classes we don&apos...

You have been reading a chapter from
Swift By Example
Published in: Jun 2015
Publisher:
ISBN-13: 9781785284700
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image