星空网 > 软件开发 > 操作系统

【代码笔记】自定义开关

一,效果图。

【代码笔记】自定义开关images/loading.gif' data-original="http://images2015.cnblogs.com/blog/337518/201510/337518-20151022134001442-998974671.jpg" width="218" height="400" />

二,工程图。

【代码笔记】自定义开关

三,代码。

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 toggleViewWithLabel;@synthesize toggleViewWithoutLabel;@synthesize toggleViewBaseChange;@synthesize toggleViewButtonChange;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  if (self) {    // Custom initialization  }  return self;}- (void)viewDidLoad{  [super viewDidLoad];  // Do any additional setup after loading the view.      //可以通过换图片,而为成自己需要的按钮。     [[self navigationController] setNavigationBarHidden:YES animated:YES];    toggleViewWithLabel = [[ToggleView alloc]initWithFrame:CGRectMake(0, 50, 320, 75) toggleViewType:ToggleViewTypeWithLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeDefault];  toggleViewWithLabel.toggleDelegate = self;    toggleViewWithoutLabel = [[ToggleView alloc]initWithFrame:CGRectMake(0, 150, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeDefault];  toggleViewWithoutLabel.toggleDelegate = self;    toggleViewBaseChange = [[ToggleView alloc]initWithFrame:CGRectMake(0, 250, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeChangeImage toggleButtonType:ToggleButtonTypeDefault];  toggleViewBaseChange.toggleDelegate = self;    toggleViewButtonChange = [[ToggleView alloc]initWithFrame:CGRectMake(0, 350, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeChangeImage];  toggleViewButtonChange.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.";  label1.backgroundColor = [UIColor clearColor];  label2.backgroundColor = [UIColor clearColor];  label3.backgroundColor = [UIColor clearColor];  label4.backgroundColor = [UIColor clearColor];  label1.font = [UIFont boldSystemFontOfSize:14];  label2.font = [UIFont boldSystemFontOfSize:14];  label3.font = [UIFont boldSystemFontOfSize:14];  label4.font = [UIFont boldSystemFontOfSize: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:ToggleButtonSelectedRight];  [toggleViewButtonChange setSelectedButton:ToggleButtonSelectedRight];  }#pragma -mark - ToggleViewDelegate- (void)selectLeftButton{  NSLog(@"LeftButton Selected");}- (void)selectRightButton{  NSLog(@"RightButton Selected");}- (void)didReceiveMemoryWarning{  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}
【代码笔记】自定义开关

 




原标题:【代码笔记】自定义开关

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Shopee运营:新手卖家做Shopee可收藏的运营攻略:https://www.ikjzd.com/articles/135087
店铺装修技巧大解析 为你解决低流量低转化烦恼!:https://www.ikjzd.com/articles/135088
季节性产品明明有流量优势,为何做不好?:https://www.ikjzd.com/articles/135089
Wish:符合条件的A+、EPC订单免除延迟到仓费,揽收费还8折!:https://www.ikjzd.com/articles/135090
英国公司成立后不年审会怎样?:https://www.ikjzd.com/articles/135092
破案了!亚马逊购PS5变空气炸锅,原来是...:https://www.ikjzd.com/articles/135093
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流