One.
Two, engineering drawings.
Three, code.
ViewController.h
#import <UIKit/UIKit.h>"CustomSwitch.h"@interface Viewcontroller: Uiviewcontroller@property (nonatomic, Strong) Customswitch * leftswitch; @property (nonatomic, Strong) CustomSwitch * Rightswitch; @end
Viewcontroller.m
#import"ViewController.h"#import"CustomSwitch.h"#define Tag_color Bottom_click_color#define Bottom_click_color COLOR (41, 115, 192, 1)#define Color (R, G, b,d) [Uicolor colorwithred: (r)/255.0 Green: (g)/255.0 Blue: (b)/255.0 Alpha:d]@interfaceViewcontroller ()@end@implementationviewcontroller-(void) Viewdidload {[Super viewdidload];//Additional setup after loading the view, typically from a nib.//Initialize the selection box page[Self addswitchview];}#pragma-mark-functions//Initialize the selection box page-(void) addswitchview{Customswitch *leftswitch = [[Customswitch alloc]initwithframe:cgrectmake (20,100,200,) Oncolor:tag_color Offcolor:color (214,214,214,1) Font:[uifont Systemfontofsize:Ballsize]:25]; Leftswitch.ontext =@"Technical support"; Leftswitch.offtext =@"No technical support"; leftswitch.userinteractionenabled =YES; Leftswitch.on =NO; Leftswitch.tag =0; [Leftswitch addtarget:self Action: @selector (Handletapleftswitch:) forcontrolevents:uicontroleventvaluechanged]; [Self.view Addsubview:leftswitch]; Customswitch *rightswitch = [[Customswitch alloc]initwithframe:cgrectmake (20,200,200,) Oncolor:tag_color Offcolor:color (214,214,214,1) Font:[uifont Systemfontofsize:Ballsize]:25]; Rightswitch.ontext =@"has been resolved"; Rightswitch.offtext =@"Not resolved"; rightswitch.userinteractionenabled =YES; Rightswitch.on =NO; Leftswitch.tag =1; [Rightswitch addtarget:self Action: @selector (Handletaprightswitch:) forcontrolevents:uicontroleventvaluechanged]; [Self.view Addsubview:rightswitch];}#pragma-mark-functions//Left button click Event-(void) Handletapleftswitch: (Customswitch *) customswitch{NSLog (@ " Left button click event "// Right button click Event-(void) Handletaprightswitch: (customswitch *@ " Right button click event " );} -(void) didreceivememorywarning {[Super Didreceivememorywarning]; // Dispose of any resources this can be Recreated.} @end
"Code note" ios-Custom switch