【代码笔记】iOS-自定义开关
一,效果图。
二,工程图。
三,代码。
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.
}

【代码笔记】iOS-自定义开关的更多相关文章
- iOS 自定义导航栏笔记
一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- Hadoop学习笔记—5.自定义类型处理手机上网日志
转载自http://www.cnblogs.com/edisonchou/p/4288737.html Hadoop学习笔记—5.自定义类型处理手机上网日志 一.测试数据:手机上网日志 1.1 关于这 ...
- OpenGL ES: iOS 自定义 UIView 响应屏幕旋转
iOS下使用OpenGL 如果使用GLKit View 那么不用担心屏幕旋转的问题,说明如下: If you change the size, scale factor, or drawable pr ...
- iOS 自定义转场动画
代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- iOS自定义转场动画实战讲解
iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...
随机推荐
- 使用EntityFramework6连接MySql数据库(code first方式)
demo托管地址:http://git.oschina.net/uustudy/ASP.NET-CodeFirst-MySQL-Demo.git 之前的是db first(地址:http://www. ...
- Goodbye2014,Hello2015
正如我在研发会议上说的,总结是为了更好的计划:而计划,则是让你做事有目标,有方向:有了目标和方向,你才能真正把事情做成! 总的来说2014年可以归纳为下图: 2014年总结 一年的活动,基本可以归纳为 ...
- [Intel Edison开发板] 04、Edison开发基于nodejs和redis的服务器搭建
一.前言 intel-iot-examples-datastore 是Intel提供用于所有Edison开发板联网存储DEMO所需要的服务器工程.该工程是基于nodejs和redis写成的一个简单的工 ...
- AngularJs之六(服务)
服务:AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用.AngularJS 内建了30 多个服务. 最常用的服务:$location 服务, $http 服务 ...
- node.js学习总结(一)
1.1.1 安装 Node.js 有三种方式安装 Node.js:一是通过安装包安装,二是通过源码编译安装,三是在 Linux 下可以通过 yum|apt-get 安装,在 Mac 下可以通过 Hom ...
- 3. 解析 struts.xml 文件
1. struts.xml 文件基本配置: 主要放在资源路径下,配置 sturts2相关的 Action , 拦截器等配置 <struts> <!-- 设置常量 --> < ...
- 对C语言islower、isupper、isdigit函数的测试
今天朋友问起了这三个函数,我就帮忙测试了下,测试后发现谭浩强第四版课本附录上上讲的不是很严谨. 我们先看下这三个函数介绍: 谭浩强第四版课本附录第396页上这样介绍: 函数名 函数原型 功能 返回值 ...
- ASP.NET Core 中文文档 第三章 原理(1)应用程序启动
原文:Application Startup 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:谢炀(kiler398).许登洋(Seay) ASP.NET Core 为你的应用程 ...
- MyCat源码分析系列之——SQL下发
更多MyCat源码分析,请戳MyCat源码分析系列 SQL下发 SQL下发指的是MyCat将解析并改造完成的SQL语句依次发送至相应的MySQL节点(datanode)的过程,该执行过程由NonBlo ...
- 自己封装的一个原生JS拖动方法。
代码: function drag(t,p){ var point = p || null, target = t || null, resultX = 0, resultY = 0; (!point ...