一,效果图。

二,工程图。

三,代码。

ViewController.h

#import <UIKit/UIKit.h>
#import "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] @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//初始化选择框页面
[self addSwitchView];
}
#pragma -mark -functions
//初始化选择框页面
-(void)addSwitchView
{
CustomSwitch *leftSwitch = [[CustomSwitch alloc]initWithFrame:CGRectMake(20, 100, 200, 50) onColor:TAG_COLOR offColor:Color(214, 214, 214, 1) font:[UIFont systemFontOfSize:15] ballSize:25]; leftSwitch.onText = @"技术支持";
leftSwitch.offText = @"未技术支持";
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, 50) onColor:TAG_COLOR offColor:Color(214, 214, 214, 1) font:[UIFont systemFontOfSize:15] ballSize:25];
rightSwitch.onText = @"已解决";
rightSwitch.offText = @"未解决";
rightSwitch.userInteractionEnabled = YES;
rightSwitch.on = NO;
leftSwitch.tag = 1;
[rightSwitch addTarget:self action:@selector(handleTapRightSwitch:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:rightSwitch]; }
#pragma -mark -functions
//左侧按钮点击事件
- (void)handleTapLeftSwitch:(CustomSwitch *)customSwitch
{
NSLog(@"左侧按钮点击事件");
}
//右侧按钮点击事件
- (void)handleTapRightSwitch:(CustomSwitch *)customSwitch
{
NSLog(@"右侧按钮点击事件"); } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

【代码笔记】iOS-自定义switch的更多相关文章

  1. 【代码笔记】Web-JavaScript-JavaScript switch语句

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. iOS 自定义导航栏笔记

    一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...

  3. iOS自定义的UISwitch按钮

    UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...

  4. iOS 自定义转场动画浅谈

    代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...

  5. iOS自定义转场动画实战讲解

    iOS自定义转场动画实战讲解   转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerA ...

  6. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  7. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  8. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  9. Hadoop学习笔记—5.自定义类型处理手机上网日志

    转载自http://www.cnblogs.com/edisonchou/p/4288737.html Hadoop学习笔记—5.自定义类型处理手机上网日志 一.测试数据:手机上网日志 1.1 关于这 ...

  10. OpenGL ES: iOS 自定义 UIView 响应屏幕旋转

    iOS下使用OpenGL 如果使用GLKit View 那么不用担心屏幕旋转的问题,说明如下: If you change the size, scale factor, or drawable pr ...

随机推荐

  1. tomcat服务的启动与隐藏启动(win)

    一:  tomcat的启动与隐藏启动 1. 正常启动:D:\apache-tomcat-8.5.24\bin中的   startup.bat  双击启动 2. 启动tomcat服务后,window下方 ...

  2. requests请求例子

    实例一: class GetSalerInfo(View): def post(self, request): userid = request.POST/GET.get('userid',None) ...

  3. Docker三剑客之Docker Compose

    一.什么是Docker Compose Compose 项目是Docker官方的开源项目,负责实现Docker容器集群的快速编排,开源代码在https://github.com/docker/comp ...

  4. odoo配置界面设置字段默认值

    转自国外牛人博客:http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html Defining custom settings in O ...

  5. Dev Label显示不同颜色字体

    labelControl1.Text = "<size=14>Size = 14<br>" + "<b>Bold</b> ...

  6. 剑指offer三从头到尾打印链表

    一.题目: 输入一个链表,从尾到头打印链表每个节点的值. 二.解题方法: 方法一:采用递归的方式实现 方法二:借助堆栈的“后进先出”实现 import java.util.ArrayList; imp ...

  7. COM+时代的自动事务

    最近看公司的遗留项目代码,调试的时候发现经常报分布式事务错误,可是整个代码里没有看见开启过事务,于是开始研究,发现了这个.Net Framework1.1时代的产物. namespace Busine ...

  8. JavaScript -- Location

    -----043-Location.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=&quo ...

  9. PHP 编程小点

    1.全局变量,$global 2.引用.函数返回引用.写时拷贝.对象复制.clone.unset.$varname=null 3.函数作用域,但是没有块级作用域 4.php7 新特性 5.autolo ...

  10. [Python学习笔记-005] 理解yield

    网络上介绍yield的文章很多,但大多讲得过于复杂或者追求全面以至于反而不好理解.本文用一个极简的例子给出参考资料[1]中的讲解,因为个人觉得其讲解最为通俗易懂,读者只需要对Python的列表有所了解 ...