"Code note" ios-Custom switch

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.