Possible Duplicate:
Checkbox in IPhone application
I want to create a simple checkbox with 2 values and save this, how can I make that?
Thanks.
For example, iOS, iPadOS, macOS, and watchOS support the switch toggle style, whereas only macOS supports the checkbox style.
There is absolutely no need to create a custom View with a checkbox image or anything like that. Simply use the Toggle SwiftUI element with a styling set to CheckboxToggleStyle(). That is all you need to create native checkboxes in SwiftUi.
Yeah, no checkbox for you in iOS (-:
Here, this is what I did to create a checkbox:
UIButton *checkbox; BOOL checkBoxSelected; checkbox = [[UIButton alloc] initWithFrame:CGRectMake(x,y,20,20)]; // 20x20 is the size of the checkbox that you want // create 2 images sizes 20x20 , one empty square and // another of the same square with the checkmark in it // Create 2 UIImages with these new images, then: [checkbox setBackgroundImage:[UIImage imageNamed:@"notselectedcheckbox.png"] forState:UIControlStateNormal]; [checkbox setBackgroundImage:[UIImage imageNamed:@"selectedcheckbox.png"] forState:UIControlStateSelected]; [checkbox setBackgroundImage:[UIImage imageNamed:@"selectedcheckbox.png"] forState:UIControlStateHighlighted]; checkbox.adjustsImageWhenHighlighted=YES; [checkbox addTarget:(nullable id) action:(nonnull SEL) forControlEvents:(UIControlEvents)]; [self.view addSubview:checkbox];
Now in the target method do the following:
-(void)checkboxSelected:(id)sender { checkBoxSelected = !checkBoxSelected; /* Toggle */ [checkbox setSelected:checkBoxSelected]; }
That's it!
On iOS there is the switch UI component instead of a checkbox, look into the UISwitch
class. The property on
(boolean) can be used to determine the state of the slider and about the saving of its state: That depends on how you save your other stuff already, its just saving a boolean value.
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