[IOS] Check box

 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];

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326266834&siteId=291194637