O'Reilly logo

Swift Game Development - Third Edition by Stephen Haney, Siddharth Shekar

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

Creating a UI for the app

We will now create some UI-like buttons for hosting and joining a session and a Map button to send the map once we have connected to a peer. We will also create a couple of text labels to tell us what the app is doing currently.

For sending the map, we will create a custom class so that the button lights up when the map is ready to be sent.

Create a new Swift file called RoundedButton. In it, create a new class of the same name and inherit from UIButton:

import UIKit

@IBDesignable
class RoundedButton: UIButton {

    
}

In this class, we will add the init function, which will, in turn, call the setup() function in which we will set the button parameters.

Also, override the isEnabled function, which, when set, will change backgroundColor ...

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