ios-UISwitch

let mySwitch:UISwitch = UISwitch(frame: CGRect(x:0,y:80,witdh:10,height:10)

//添加触发事件

mySwitch.addTarget(self,action:Selector("SwitchClick:")),forControlEvents:UIControlEvents.valueChanged)

//设置滑块的颜色

myswitch.thumbTintcolor = UIColor.red

//设置开关开启的颜色

mySwitch.ontintColor = UIColor.blue

//关闭开关的颜色

mySwitch.tintColor = UIColor.blue

 

//函数

func switchClick(swi:UISwitch){

  if swi.on{

    self.view.backgroudColor = UIColor.gray

  }else{

    self.view.backgroudcolor = UIcolor.blue

  }

}

posted @ 2018-09-10 20:40  知津楼上风好大  阅读(143)  评论(0编辑  收藏  举报