Recipe: Animating Button Responses

There’s more to UIControl instances than frames and target-action. All controls inherit from the UIView class. This means you can use UIView animation blocks when working with controls just as you would with standard views. Recipe 2-2 builds a toggle switch that zooms itself whenever a user touches it and returns to its original size when the touch leaves the control.

This recipe creates a livelier interaction element that helps focus greater attention on the control in question.

Note

To add a little flare to your instances, note that buttons support delicious NSAttributedString values via setAttributedTitleForState:. Recipe 2-4, which follows later in this chapter, updates a segmented control’s text color ...

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.