swift中UISwitch的使用

  1. // 实例化(注意:默认宽高是 51 x 31。指定大小无效)  
  2. let switchview = UISwitch(frame: CGRectMake(10.0, 10.0, 0.0, 0.0))  
  3. self.view.addSubview(switchview)  
  4. switchview.backgroundColor = UIColor.yellowColor()  
  5.           
  6. // 打开时背景色  
  7. switchview.onTintColor = UIColor.brownColor()  
  8. // 开关块颜色  
  9. switchview.thumbTintColor = UIColor.blueColor()  
  10. // 关闭时边框颜色  
  11. switchview.tintColor = UIColor.orangeColor()  
  12.           
  13. // 开关图标设置(设置后无效??)  
  14. switchview.onImage = UIImage(named: "normalImage")  
  15. switchview.offImage = UIImage(named: "hightImage")  
  16.           
  17. // 初始化开,或关  
  18. switchview.setOn(false, animated: true)  
  19.           
  20. // 响应事件  
  21. switchview.addTarget(self, action: Selector("switchValueChange:"), forControlEvents: UIControlEvents.ValueChanged)  
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // MARK: - switchValueChange  
  2. func switchValueChange(sender:UISwitch)  
  3. {  
  4.         let openStatus = sender.on  
  5.         if openStatus  
  6.         {  
  7.             self.view.backgroundColor = UIColor.cyanColor()  
  8.         }  
  9.         else  
  10.         {  
  11.             self.view.backgroundColor = UIColor.whiteColor()  
  12.         }  
  13. }  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值