Use a UIButton
instead of a UILabel
and set an IBAction
on it. You can style the button to look exactly like the label. Your IBAction
method should look something like this:
- (void)buttonPressed:(UIButton *)sender
{
//Get the view by tag
UISwitch *mySwitch = (UISwitch *)[self.view viewWithTag:yourTag];
[mySwitch.setOn:![mySwitch isOn]];
}
Edit
As mentioned, since you're building the UIButton
s in code, you need to add the target to the button to get the button click. Add the action as such:
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];