I am new to Objective-C so i am mostly using Storyboard, Someone Please tell me how to create a checkbox
using Xcode in iOS.
-
You need to create UITableView with multiple selection. – Nirav D Jun 14 '16 at 10:27
-
how to do that could you please elaborate. – Jun 14 '16 at 10:28
-
How do we determine what version of xCode this question was asked under? – Mark Puchala II Aug 14 '18 at 04:48
6 Answers
UISwitch
is the standard control used in iOS for indicating an on/off, selected/unselected state. Why not use that?

- 118,105
- 32
- 252
- 268
-
what if i have to use agree condition and before that i have to use check terms and conditions. – Jun 14 '16 at 11:21
UISwitch is the standard control used in IOS applications for making binary choices but if you want to use checkbox you can create a UIButton
@property (weak, nonatomic) IBOutlet UIButton *CheckBox;
- (IBAction)CheckBoxClick:(id)sender
and change its background image on click event of UIButton
- (IBAction)CheckBoxClick:(id)sender {
if(!checked){
[_CheckBox setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
checked = YES;
}
else if(checked){
[_CheckBox setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
checked = NO;
}
}
also there are more detailed answers to this question at
How to create a simple checkbox in iOS?
and if you dont want to use images you can check the following
CheckBox is not available in object library. You can use third party library for that purpose or you can create it by your self.
There is the working code for checkbox.
create a class level variable and property of button in @inteface
@interface testViewController (){
BOOL checkBoxSelected;
}
@property (weak, nonatomic) IBOutlet UIButton *checkBox;
@end
in viewdidload set images for the button states.
[_checkBox setBackgroundImage:[UIImage imageNamed:@"checkBoxUnChecked.png"]
forState:UIControlStateNormal];
[_checkBox setBackgroundImage:[UIImage imageNamed:@"checkBoxChecked.png"]
forState:UIControlStateSelected];
and after create a button action in that button Action.
checkBoxSelected = !checkBoxSelected; /* Toggle */
[_checkBox setSelected:checkBoxSelected];
Hope it helps

- 2,386
- 1
- 20
- 34
1) Create Prototype cell in UITableView.
2) Add one button inside the cell and set button style to Custom.
3) Set the image for checkbox.

- 2,610
- 1
- 12
- 25
ios language doesn't use checkbox controller. but you are use checkbox that you are inport two image select & unselect
Step 1> Create button and set image.
Step 2> Create button touch object method and put if condition for check & uncheck. for example:
- (IBAction)btnLogin:(id)sender {
UIButton *btn = (UIButton *)sender;
if (btn.tag == 0) {
btn.tag = 1;
//set image checked.
}
else{
btn.tag = 0;
//set image unchecked.
}
}

- 3,147
- 2
- 21
- 41
You shouldn't need to subclass the UIButton class. By design, Objective-C favors composition over inheritance.
UIButton is a subclass of UIControl, which has a selected property. You can use this property to toggle the on/off behaviour of a checkbox, just the same way a UISwitch does.
You can attach an action to the button's touched up inside event, and perform the toggling in there, something like this:
// when you setup your button, set an image for the selected and normal states
[myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateSelected];
[myCheckBoxButton setImage:nonCheckedImage forState:UIControlStateNormal];
- (void)myCheckboxToggle:(id)sender
{
myCheckboxButton.selected = !myCheckboxButton.selected; // toggle the selected property, just a simple BOOL
}

- 2,258
- 19
- 34