UIKit学习之开关控件UISwitch的用法
UISwitch是一个开关控件。
UISwitch控件的创建:
(1) 在Stroyboard中使用Ctrl+Drag拖拽法创建
(2) 代码创建UISwitch:
letmySwitch=UISwitch()//设置位置(开关大小无法设置)mySwitch.center=CGPointMake(100,50);//设置默认值(开true/关false)mySwitch.on=true;self.vIEw.addSubvIEw(mySwitch);
代码实例:
//VIEwController.swiftimportUIKitclassVIEwController:UIVIEwController{overrIDefuncvIEwDIDLoad(){super.vIEwDIDLoad()//DoanyadditionalsetupafterloadingthevIEw,typicallyfromanib.letmySwitch=UISwitch()//设置位置(开关大小无法设置)mySwitch.center=CGPointMake(100,50);//设置默认值(开true/关false)mySwitch.on=true;mySwitch.addTarget(self,action:"switchDIDChanged:",forControlEvents:UIControlEvents.ValueChanged)self.vIEw.addSubvIEw(mySwitch);}//funcswitchDIDChanged(sender:UISwitch){if(sender.on){self.vIEw.backgroundcolor=UIcolor.browncolor()myLabel.text="开关已经打开";myLabel.backgroundcolor=UIcolor.bluecolor()}else{self.vIEw.backgroundcolor=UIcolor.blackcolor()myLabel.text="开关已经关闭"myLabel.backgroundcolor=UIcolor.greencolor()}}overrIDefuncdIDReceiveMemoryWarning(){super.dIDReceiveMemoryWarning()//dispoSEOfanyresourcesthatcanberecreated.}}
开发环境:
XcodeVersion 7.0 (7A220)
参考资料:
http://www.hangge.com/blog/cache/detail_532.HTML
http://www.chuanke.com/1266915-124765.HTML
总结以上是内存溢出为你收集整理的[Swift]UIKit学习之滑块控件UISwitch的用法全部内容,希望文章能够帮你解决[Swift]UIKit学习之滑块控件UISwitch的用法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)