Is there any checkbox control in the object library for iOS applications? The nearest thing I see is the switch control, which can take a boolean value.
A toggle lets people choose between a pair of opposing states, like on and off, using a different appearance to indicate each state. 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.
A radio button displays the setting of something in your application and is part of a group in which only one button can be on at a time. Use a group of radio buttons to choose among several options which are mutually exclusive.
Go to Settings > Accessibility > Switch Control and turn the setting on or off.
You can use the selected state of a UIButton, set different images (or also texts) for differents (via code, or Interface Builder) :
[button setImage:[UIImage imageNamed:@"selected.png"]
forState:UIControlStateSelected];
[button setImage:[UIImage imageNamed:@"unselected.png"]
forState:UIControlStateNormal];
And in the touch up inside action :
- (IBAction)buttonTouched:(id)sender
{
button.selected = !button.selected;
// add other logic
}
//define property of button
Declare Unchecked Image
- (void)viewDidLoad
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
}
Checked Image.
- (IBAction)buttonTapped:(id)sender
{
if (_checkboxButton.selected == YES)
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateSelected];
_checkboxButton.selected = NO;
}
else
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
_checkboxButton.selected = YES;
}
}
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