import
UIKit
class
ViewController
:
UIViewController
{
var
uiswitch:
UISwitch
!;
override
func
viewDidLoad() {
super
.viewDidLoad()
uiswitch =
()
//设置位置(开关大小无法设置)
uiswitch.center=
CGPointMake
(100,50);
//设置默认值
uiswitch.on=
true
;
uiswitch.addTarget(
self
,action: #selector(switchDidChange),
forControlEvents:
UIControlEvents
.
ValueChanged
)
.view.addSubview(uiswitch);
}
switchDidChange(){
//打印当前值
print
(uiswitch.on)
}
}