Recipe: Building a Star Slider

Rating sliders allow users to grade items such as movies, software, and so forth by dragging their fingers across a set of images. It’s a common task for touch-based interfaces but one that’s not well served by a simple UISlider instance, with its floating-point values. Instead, a picker like the one built in Recipe 2-6 limits a user’s choice to a discrete set of elements, producing a bounded integer value between zero and the maximum number of items shown. As a user’s finger touches each star, the control’s value updates, and a corresponding event is spawned, allowing your application to treat the star slider like any other UIControl subclass.

The art is arbitrary. The example shown in Figure 2-6 uses stars, but ...

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.