Suchi Suchi - 1 year ago 200
iOS Question

iOS - How to set a UISwitch programmatically

I want to set my UISwitch to on or off programmatically. How would I do that? I am an iOS newbie.

Answer Source

I'm not familiar with a 'checkbox' in iOS, but if you are using a UISwitch, then as seen in the developper API, the task setOn: animated: should do the trick.

- (void)setOn:(BOOL)on animated:(BOOL)animated

So to set the switch ON in your program, you would use:


[switchName setOn:YES animated:YES];


switchName.setOn(true, animated: true)