Recipe: Building a Custom Lock Control

We created the lock control you see in Figure 2-8 for a conference after wrapping up the last edition of this Cookbook. At that time, numerous people asked for this recipe to be included in the next edition. It’s surprisingly easy to build from a UIControl point of view. It consists of four elements: a backdrop, the lock image (which switches to an unlocked version on success), the drag track, and the thumb.

Image

Figure 2-8 This simple lock control unlocks and removes itself after the user successfully swipes across at least three-quarters of the way.

Recipe 2-9 shows the code that creates this control’s behavior. ...

Get The Core iOS Developer’s Cookbook, Fifth Edition 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.