Working with Switches and Steppers

The UISwitch object offers a simple on/off toggle that lets users choose a Boolean value. The switch object contains a single (settable) value property, called on. This property returns either YES or NO, depending on the current state of the control. You can programmatically update a switch’s value by changing the property value directly or calling setOn:animated:, which offers a way to animate the change:

- (void)didSwitch:(UISwitch *)theSwitch {     self.title = [NSString stringWithFormat:@"%@"         theSwitch.on ? @"On" : @"Off"]; } - (void)viewDidAppear:(BOOL)animated {     [super viewDidAppear:animated];     // Create the switch     UISwitch *theSwitch = [[UISwitch alloc] ...

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.