O'Reilly logo

Swift 2 By Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 View Controller class in order to implement the menu screen.

From the mockup, we can observe that there are three difficulty levels, each represented by a horizontally centered and vertically equidistant button.

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

Then, we implement the setup for the layout:

enum Difficulty {
    case Easy, Medium, Hard
}

This enum must be defined outside the class so that it will be accessible by all classes.

Just for the sake of readability, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required