swift UISwitch

来源:互联网 发布:淘宝商品降权查询 编辑:程序博客网 时间:2024/06/05 04:54

/* 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

    }

    

0 0
原创粉丝点击