I need to add checkbox controls to my form. I know that there is no such control in iOS SDK. How could I do this?
Different platforms can support various toggle styles. For example, iOS, iPadOS, macOS, and watchOS support the switch toggle style, whereas only macOS supports the checkbox style. In addition, all platforms support buttons that enable toggle behavior by using a different appearance for each state.
this has been driving me mad too and I found a different solution that works well for me and avoids having to use images.
You might want to call the togglePaidStatus function in the viewDidLoad function to set it to an empty string initially.
Obviously you can add extra checks to prevent users toggling the checkbox if the label is not enabled, but that's not shown below.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if (CGRectContainsPoint([fullyPaid frame], [touch locationInView:self.view])) { [self togglePaidStatus]; } } -(void) togglePaidStatus { NSString *untickedBoxStr = [[NSString alloc] initWithString:@"\u2610"]; NSString *tickedBoxStr = [[NSString alloc] initWithString:@"\u2611"]; if ([fullyPaid.text isEqualToString:tickedBoxStr]) { fullyPaid.text = untickedBoxStr; } else { fullyPaid.text = tickedBoxStr; } [tickedBoxStr release]; [untickedBoxStr release]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With