There is no checkbox or radio button in IOS, which is quite speechless for android kids shoes. It doesn't matter. We can write a view to implement our own tickets 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
[Cpp]
01. # import <UIKit/UIKit. h>
02.
03. @ interface UICheckBox: UIButton
04.
05. @ end
# Import <UIKit/UIKit. h>
@ Interface UICheckBox: UIButton
@ EndUICheckBox. m
[Cpp]
01. # import "UICheckBox. h"
02.
03. @ implementation UICheckBox
04.
05.-(id) initWithFrame :( CGRect) frame
06 .{
07. self = [super initWithFrame: frame];
08. if (self ){
09. [self setBackGroundImage];
10 .}
11. return self;
12 .}
13.-(void) setBackGroundImage {
14. [self setBackgroundImage: [UIImage imageNamed: @ "unchecked.png"] forState: UIControlStateNormal];
15. [self setBackgroundImage: [UIImage imageNamed: @ "checked.png"] forState: UIControlStateSelected];
16. [self addTarget: self action: @ selector (touchUIInside :) forControlEvents: UIControlEventTouchUpInside];
17 .}
18.
19.-(id) initWithCoder :( NSCoder *) aDecoder {
20. self = [super initWithCoder: aDecoder];
21. if (self ){
22. [self setBackGroundImage];
23 .}
24. return self;
25 .}
26.
27.-(IBAction) touchUIInside :( id) sender {
28. UICheckBox * cb = (UICheckBox *) sender;
29. cb. selected =! Cb. selected;
30.
31 .}