Adding Efficiency

Recipe 2–3 stores a previous value for the slider to minimize the overall computational burden on iOS. It updates the thumb with a new custom image when the slider has changed by at least 0.1, or 10% in value. You can omit this check, if you want, and run the recipe with full live updating. This provided reasonably fast updates even on a first-generation iPod touch unit. On recent iPhones and iPads, it has no performance issues at all.

This recipe also avoids any issues at the ends of the slider—namely when the thumb gets caught at 0.9 and won’t update properly to 1.0. In this recipe, a hard-coded workaround for values above 0.98 handles that particular situation by forcing updates.

Recipe 2-3 Building Dynamic Slider Thumbs ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.