Implementing the ThermostatSlider control
The first step is to subclass UIControl
by creating a new file in Xcode and giving a name to the new class; ThermostatSlider
sounds about right.
Note
Note that at any time during the explanation, you can check the full source code to verify how to move from one step to the next one. During the chapter, we will describe only the key parts of the implementation.
A good practice that helps you keep your code clean is using the // MARK:
comment to separate the projects in subsections. To be consistent with the chapter, the code that you'll find for this project is split into four main sections: initialization, design, update, and touch tracking. We will now examine them one by one.
Control initialization
It is good practice to keep the code readable and, when possible, split logics into simple independent functions. In some cases, writing comments is almost redundant; good code can be automatically documented using clear names for variables and methods. For...