加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift中UISwitch的使用

发布时间:2020-12-14 06:42:08 所属栏目:百科 来源:网络整理
导读:// 实例化(注意:默认宽高是 51 x 31。指定大小无效)let switchview = UISwitch(frame: CGRectMake(10.0,10.0,0.0,0.0))self.view.addSubview(switchview)switchview.backgroundColor = UIColor.yellowColor() // 打开时背景色switchview.onTintColor = UI
// 实例化(注意:默认宽高是 51 x 31。指定大小无效)
let switchview = UISwitch(frame: CGRectMake(10.0,10.0,0.0,0.0))
self.view.addSubview(switchview)
switchview.backgroundColor = UIColor.yellowColor()
        
// 打开时背景色
switchview.onTintColor = UIColor.brownColor()
// 开关块颜色
switchview.thumbTintColor = UIColor.blueColor()
// 关闭时边框颜色
switchview.tintColor = UIColor.orangeColor()
        
// 开关图标设置(设置后无效??)
switchview.onImage = UIImage(named: "normalImage")
switchview.offImage = UIImage(named: "hightImage")
        
// 初始化开,或关
switchview.setOn(false,animated: true)
        
// 响应事件
switchview.addTarget(self,action: Selector("switchValueChange:"),forControlEvents: UIControlEvents.ValueChanged)
// MARK: - switchValueChange
func switchValueChange(sender:UISwitch)
{
        let openStatus = sender.on
        if openStatus
        {
            self.view.backgroundColor = UIColor.cyanColor()
        }
        else
        {
            self.view.backgroundColor = UIColor.whiteColor()
        }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读