========================================================== =============================== Original blog, reprinted please declare the source of Electronic coffee (original id blue rock) ========================================================== ============================== there is no checkbox or radio button in iOS, this is quite speechless for kids shoes that have done Android. It doesn't matter. We write a view to implement our own single and check boxes. First, add two images to your resource. One is the selected status of the button, and the other is the unselected status, named unchecked.pngand checked.png respectively. The following code is displayed. I believe you can understand it ., If you have any questions, please leave a message. Uicheckbox. h
#import <UIKit/UIKit.h>@interface UICheckBox : UIButton@end
Uicheckbox. m
#import "UICheckBox.h"@implementation UICheckBox- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { [self setBackGroundImage]; } return self;}- (void)setBackGroundImage { [self setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal]; [self setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected]; [self addTarget:self action:@selector(touchUIInside:) forControlEvents:UIControlEventTouchUpInside];}-(id)initWithCoder:(NSCoder *)aDecoder{ self = [super initWithCoder:aDecoder]; if (self) { [self setBackGroundImage]; } return self;}-(IBAction)touchUIInside:(id)sender{ UICheckBox* cb= (UICheckBox*)sender; cb.selected = !cb.selected; }