您的位置:首页 > 移动开发 > Swift

swift UISwitch

2016-12-23 09:29 78 查看
/* swift 3.0    UISwitch的使用  */
        
        /* 创建UISwitch 
            
            UISwitch具有默认的高宽,所以只要设置位置就可以了;
         
         */
        let uiswitch:UISwitch =
UISwitch()
        uiswitch.center =
view.center
        uiswitch.isOn =
true  /*
开关默认打开 */
        uiswitch.addTarget(self, action:
#selector(switchDidChange), for: .valueChanged)
        view.addSubview(uiswitch)
        uiswitch.bounds =
CGRect.init(x:
0, y: 0, width:
100, height: 100)
    }
    
    
    func switchDidChange( sender:
UISwitch ){
        
        if  sender.isOn {
            
            print("开")
        } else {
            
            print("关")
        }
//        sender.isOn = !sender.isOn
    }
    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: