I want to add checkboxes and have a title for each checkbox and have if certain boxes are checked then it displays certain texts like
if box 1 then displays text1
if box 2 is selected then displays text2
I want to add checkboxes and have a title for each checkbox and have if certain boxes are checked then it displays certain texts like
if box 1 then displays text1
if box 2 is selected then displays text2
Try this ,
UIButton *buttonCheckbox = [[UIButton alloc] initWithFrame:CGRectMake(10, 12,20, 20)];
[buttonCheckbox addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];
- (void)toggleButton: (id) sender
{
UIButton *tappedButton = (UIButton*)sender;
NSLog(@"%d",tappedButton.tag);
if([tappedButton.currentImage isEqual:[UIImage imageNamed:@"checkbox.png"]])
{
[sender setImage:[UIImage imageNamed: @"checkbox-checked.png"] forState:UIControlStateNormal];
}
else
{
[sender setImage:[UIImage imageNamed: @"checkbox.png"] forState:UIControlStateNormal];
}
You can find on Cocoa Controls some custom controls that implement checkboxes.
For example SSCheckBoxView
is one of them. You can find it on github
You are looking for UISwitch, it has the same functionality with checkbox but a different appearance. Otherwise you need to create your own checkbox possibly by customizing a UIButton.
To get updated when UISwitch's value changes you need to hook up its valueChanged event to an action.
-(IBAction) valueChanged:(UISwitch *) sender
{
if(sender.on)
{
...
}
}