Uiswitch is generally used for setting apps in iOS development, and occasionally appears monotonous. At this time, you can choose to use a third-party open-source class library sscheckboxview. Sscheckboxview is a check box UI control available on iOS. It provides two options: select and not selected, and 5.
GitHub: https://github.com/ardalahmet/SSCheckBoxView
The encapsulated sscheckboxview is easy to use. First, initialize its frame, set the display style and status, and add it to the view to display a check box.
- (void)viewDidLoad{ [super viewDidLoad]; SSCheckBoxView *cb = [[SSCheckBoxView alloc] initWithFrame:CGRectMake(50, 50, 30, 30) style:kSSCheckBoxViewStyleMono checked:YES]; [self.view addSubview:cb]; [cb release]; }
:
Five display styles. When passing parameters, you can set the display styles by passing the numbers between 0 and 5.
typedef enum SSCheckBoxViewStyle_ { kSSCheckBoxViewStyleBox = 0, kSSCheckBoxViewStyleDark, kSSCheckBoxViewStyleGlossy, kSSCheckBoxViewStyleGreen, kSSCheckBoxViewStyleMono, kSSCheckBoxViewStylesCount} SSCheckBoxViewStyle;
If you need to describe how to use the check box, set text, but you need to adapt the width of the sscheckboxview object. If the width is too short, the display is incomplete. You can observe the check box in two ways, one is the selector and the other is the block;
-(Void) viewdidload {[Super viewdidload]; sscheckboxview * cb = [[sscheckboxview alloc] initwithframe: cgrectmake (50, 50,300, 30) style: ksscheckboxviewstylemono checked: Yes]; [CB settext: @ "What is this?"]; [CB setstatechangedtarget: Self selector: @ selector (checkboxviewchangedstate :)]; [self. view addsubview: CB]; [CB release]; sscheckboxview * CB2 = [[sscheckboxview alloc] initwithframe: cgrectmake (50, 80,300, 30) style: 3 checked: Yes]; [CB2 settext: @ "Use block to check whether selected"]; [CB2 setstatechangedblock: ^ (sscheckboxview * CBV) {nslog (@ "check box status: % @", CBV. checked? @ "Selected": @ "not selected") ;}]; [self. view addsubview: CB2]; [CB2 release];}-(void) checkboxviewchangedstate :( sscheckboxview *) CBV {nslog (@ "check box status: % @", CBV. checked? @ "Selected": @ "not selected ");}
:
Original blog welcome to repost share, please indicate the source of http://blog.csdn.net/duxinfeng2010