Swift - 开关按钮(UISwitch)的用法
用法 swift 按钮 开关
2023-09-11 14:17:59 时间
下面演示如何创建开关,以及监听它值的改变,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class ViewController : UIViewController { var uiswitch: UISwitch !; override func viewDidLoad() { super .viewDidLoad() uiswitch = UISwitch () //设置位置(开关大小无法设置) uiswitch.center= CGPointMake (100,50); //设置默认值 uiswitch.on= true ; uiswitch.addTarget( self , action: Selector ( "switchDidChange" ), forControlEvents: UIControlEvents . ValueChanged ) self .view.addSubview(uiswitch); } func switchDidChange(){ //打印当前值 println (uiswitch.on) } } |
相关文章
- AppScan扫描器的用法
- python中json用法详解
- c++多个源文件共用一个全局变量(extern的用法)
- Vue - watch 三种不同写法及场景用法(immediate、handler / deep)
- Ansible 详细用法部署安装
- Oracle的substr函数简单用法
- Oracle 中union的用法
- Swift 2.x 升为 swift 3后语法不兼容问题适配
- Swift继承的用法
- Swift - 故事板storyboard的用法
- Swift - 加速传感器(CoreMotion)的用法,小球加速运动并反弹样例
- Swift - 多行文本输入框(UITextView)的用法
- [js高手之路]深入浅出webpack教程系列1-安装与基本打包用法和命令参数
- Swift - enumerateObjectsUsingBlock的用法
- SQL中object_id函数的用法