iOS - UISwitch
前言
NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UISwitch : UIControl <NSCoding>
@available(iOS 2.0, *) public class UISwitch : UIControl, NSCoding
1、Switch 的创建
Objective-C
// 实例化 switch 对象,switch 的大小是由系统固定的
UISwitch *switch1 = [[UISwitch alloc] init]; // 将 sw 添加到 view
[self.view addSubview:switch1];
Swift
// 实例化 switch 对象,switch 的大小是由系统固定的
let switch1:UISwitch = UISwitch() // 将 sw 添加到 view
self.view.addSubview(switch1)
2、Switch 的设置
Objective-C
// 设置位置
switch1.center = self.view.center; // 设置 tag 值
switch1.tag = 100; // 设置外边框颜色
switch1.tintColor = [UIColor redColor]; // 设置滑块的颜色
switch1.thumbTintColor = [UIColor blueColor]; // 设置 on 时的颜色
/*
默认为绿色
*/
switch1.onTintColor = [UIColor orangeColor]; // 设置当前的开关状态
switch1.on = YES; // 获取当前的开关状态
BOOL isOn = switch1.isOn; // 添加点击触发事件
[switch1 addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventValueChanged];
Swift
// 设置位置
switch1.center = self.view.center // 设置 tag 值
switch1.tag = 100 // 设置外边框颜色
switch1.tintColor = UIColor.redColor() // 设置滑块的颜色
switch1.thumbTintColor = UIColor.blueColor() // 设置 on 时的颜色
/*
默认为绿色
*/
switch1.onTintColor = UIColor.orangeColor() // 设置当前的开关状态
switch1.on = true // 获取当前的开关状态
let isOn:Bool = switch1.on // 添加点击触发事件
switch1.addTarget(self, action: #selector(UiSwitch.switchClick(_:)), forControlEvents: .ValueChanged)
3、Storyboard 中设置
在 Storyboard 场景中设置
Switch 设置
State 开关状态 |
On Tint | 开关开时的颜色
Thumb Tint | 开关滑块的颜色
|
On Image | 开关开时的图片
Off Image | 开关关时的图片Control 设置
Alignment 文字对齐方式 |
Content |
-- Selected | 选中
-- Enable | 可用
-- Highlighted | 高亮
iOS - UISwitch的更多相关文章
- IOS UISwitch控件的基本使用
* UISwitch继承自UIControl,因此也能像UIButton一样监听一些事件,比如状态改变事件* UISwitch可以通过拖线监听状态改变* UISwitch可以通过addTarget:. ...
- IOS UISwitch 控件
转自:http://my.oschina.net/wolx/blog/396680 一 UISwitch 简介 二 UISwitch 创建 三设置选中状态 四 添加监听 五 测试代码 5.1 代码 5 ...
- IOS 7 开发范例 - UISwitch的使用
Creating and Using Switches with UISwitch You would like to give your users the ability to turn an o ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- IOS开发UI基础UISwitch属性
UISwitch属性1. onTintColor 处于on时switch 的颜色 switchImage.onTintColor = [UIColor grayColor];2.tintC ...
- iOS开发——UI篇Swift篇&UISwitch/UIStepper
UISwitch/UIStepper override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString / ...
- iOS - UI - UISwitch
UISwitch //开关 不用设置宽高 有默认宽高 UISwitch * sw = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, ...
- UISwitch + UIimage - 初识IOS
这里解释一个小例子,希望对你有点帮助,利用UISwitch控制UIimage的动画效果 先定义一个数组,用来存放照片,现在定义数组有一个特别简单的方法: NSArray *image1 = @[]; ...
- IOS开发之XCode学习011:UISwitch控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIswitch控件,添加UIswitc ...
随机推荐
- 通过SQL Server Profiler来监视分析死锁
在两个或多个SQL Server进程中,每一个进程锁定了其他进程试图锁定的资源,就会出现死锁,例如,进程process1对table1持有1个排它锁(X),同时process1对table2请求1个排 ...
- MySQL与SQL比较有那些区别呢
MySQL是一个逐渐完善的过程,使用前期版本时会遇到一些问题,通常搞得莫名其妙,在版本选择上尽量选择最新的. 1.在5.03以前版本中,存储varchar型数据时,后面的空格会被忽视掉,前面的空格会保 ...
- hdu 1016 Prime Ring Problem(深度优先搜索)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Android 自定义ScrollView ListView 体验各种纵向滑动的需求
分类: [android 进阶之路]2014-08-31 12:59 6190人阅读 评论(10) 收藏 举报 Android自定义ScrollView纵向拖动 转载请标明出处:http: ...
- 关于AnimationState的测试
修改time信息并不会立马生效,动画信息修改是在这一帧结束统一执行的. 当normalizedTime设置为0-1之外的值时,值并不会被约束回0-1范围,而动画会被约束播放到0-1之间的位置
- Rigidbody.position/rotation更新测试
Rigidbody.position/rotation主要提供在下一个物理步之前更新物理位置,一般用于SweepTest这样的接口 那么测试一下会不会修改掉transform.position的值 测 ...
- ThreadLocal深入理解一
转载:http://www.cnblogs.com/dolphin0520/p/3920407.html 想必很多朋友对ThreadLocal并不陌生,今天我们就来一起探讨下ThreadLocal的使 ...
- torch基本命令
命令行输入th进入torch框架 命令行输入th + lua文件表示用torch执行lua文件
- (4)Redis 资料
Redis是一种面向“键/值”对类型数据的分布式NoSQL数据库系统,特点是高性能,持久存储,适应高并发的应用场景. Redis Home http://redis.io/ MSOpenTech/re ...
- dubbo子模块
dubbo源码版本:2.5.4 经统计,dubbo一共有36个子模块,子模块如下: ---------------------------------------------------------- ...