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, ...

Get Swift 2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.