[Code Note] custom switch and note custom Switch
I ,.
2. Engineering Drawing.
3. Code.
RootViewController. h
#import <UIKit/UIKit.h>#import "ToggleView.h"@interface RootViewController : UIViewController<ToggleViewDelegate>@property(nonatomic, strong)ToggleView *toggleViewWithLabel;@property(nonatomic, strong)ToggleView *toggleViewWithoutLabel;@property(nonatomic, strong)ToggleView *toggleViewBaseChange;@property(nonatomic, strong)ToggleView *toggleViewButtonChange;@end
RootViewController. m
# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController @ synthesize changes; @ synthesize toggleViewBaseChange; @ synthesize toggleViewButtonChange;-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Cu Stom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // you can change the image to the desired button. [[Self navigationController] setNavigationBarHidden: YES animated: YES]; Parameters = [[ToggleView alloc] initWithFrame: CGRectMake (0, 50,320, 75) toggleViewType: Required toggleBaseType: required parameters: toggleButtonTypeDefault]; toggleViewWithLabel. toggleDelegate = self; encoding = [[ToggleView alloc] initWithFrame: CGRectMake (0,150,320, 75) toggleViewType: Using toggleBaseType: Using toggleButtonType: ToggleButtonTypeDefault]; callback. authorization = self; toggleViewBaseChange = [[ToggleView alloc] initWithFrame: CGRectMake (0,250,320, 75) toggleViewType: Required toggleBaseType: Required toggleButtonType: callback]; toggleViewBaseChange. toggleDelegate = self; toggleViewButtonChange = [[ToggleView alloc] initWithFrame: CGRectMake (0,350,320, 75) toggleViewType: Required toggleBaseType: Required toggleButtonType: Required]; required. toggleDelegate = self; [self. view addSubview: toggleViewWithLabel]; [self. view addSubview: toggleViewWithoutLabel]; [self. view addSubview: toggleViewBaseChange]; [self. view addSubview: toggleViewButtonChange];/* label */UILabel * label1 = [[UILabel alloc] initWithFrame: CGRectMake (60, 40,200, 15)]; UILabel * label2 = [[UILabel alloc] initWithFrame: CGRectMake (60,140,200, 15)]; UILabel * label3 = [[UILabel alloc] initWithFrame: CGRectMake (60,240,200, 15)]; UILabel * label4 = [[UILabel alloc] initWithFrame: CGRectMake (60,340,200, 15)]; label1.text = @ "Toggle with label. "; label2.text = @" Toggle without label. "; label3.text = @" Toggle base image change. "; label4.text = @" Toggle button image change. "; identifier = [UIColor clearColor]; label2.backgroundColor = [UIColor clearColor]; label3.backgroundColor = [UIColor clearColor]; identifier = [UIColor clearColor]; label1.font = [UIFont identifier: 14]; label2.font = [UIFont runtime: 14]; label3.font = [UIFont runtime: 14]; runtime = [UIFont runtime: 14]; label1.alpha = 0.7f; label2.alpha = 0.7f; label3.alpha = 0.7f; label4.alpha = 0.7f; label1.textAlignment = 1; label2.textAlignment = 1; label3.textAlignment = 1; label4.textAlignment = 1; [self. view addSubview: label1]; [self. view addSubview: label2]; [self. view addSubview: label3]; [self. view addSubview: label4]; [toggleViewBaseChange setSelectedButton: Upload]; [toggleViewButtonChange setSelectedButton: Upload];} # pragma-mark-ToggleViewDelegate-(void) selectLeftButton {NSLog (@ "LeftButton Selected");}-(void) selectRightButton {NSLog (@ "RightButton Selected");}-(void) didreceivemorywarning {[super success]; // Dispose of any resources that can be recreated .}