Second-Tap Feedback

With the ability to detect a second tap, the user can be provided feedback of a reselection, such as changing the title in the navigation bar. Another alternative is modifying the attributes of the text in the segmented control. UIKit’s text attribute feature (first introduced in iOS 5.x) offers an excellent match to this challenge. Segment controls provide optional attributes based on state. The setTitleTextAttributes:forState: method lets you introduce a visual flourish limited to the selected segment. Recipe 2-4 uses this method to change the selected text color from white to red after a second tap, and it resets that change after the user selects an alternate segment, as shown in Figure 2-5.

Figure 2-5 By detecting the ...

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.