Use a third party: https://www.oschina.net/p/multiplestylecheckboxkit
1. Import Classes:
2. UI use:
*Because there is no xib control, pure code implementation, so you can use a UIView as a container in the storyboard for easy adjustment
3. Code usage:
@property (strong, nonatomic) IBOutlet UIView *checkboxView;
XHCheckBox *textCheckBox = [[XHCheckBox alloc] initWithText:NSLocalizedString(@"login_checkbox_text", @"")]; XHMultipleStyleCheckBoxView *textCheckBoxView = [[XHMultipleStyleCheckBoxView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)]; textCheckBoxView.checkBox = textCheckBox; _checkboxView.backgroundColor = [UIColor clearColor]; [_checkboxView addSubview:textCheckBoxView];
4. Set the click event:
Customize a method: For example:
-(void)checkboxAction:(UIButton *)sender{ if (sender.selected) { //Determine whether it is clicked [SessionManager setSession:@"remember_me" value:@"yes"]; NSLog(@"remember me : yes"); }else{ [SessionManager setSession:@"remember_me" value:@"no"]; NSLog(@"remember me : no"); } }
transfer:
[textCheckBoxView.checkBoxButton addTarget:self action:@selector(checkboxAction:) forControlEvents:UIControlEventTouchUpInside];