import
UIKit
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(){
//打印当前值
print
(uiswitch.on)
}
}
Swift - 开关按钮(UISwitch)的用法
转载cos_sin_tan 博主文章分类:swift
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
有趣的css - 好看的开关按钮
用css模拟实现一个好看的开关按钮动效。
css 开关按钮 动效设计 交互设计 ux/ui -
iOS UISwitch 用法总结
Switch(开关)控件的简单使用总结。
IOS UISwitch 开关控件 移动开发 UI控件