UI控件之UISwitch(事件监听)
2017-08-29 11:04
495 查看
// UISwitch
//
// Created by Catherine on 2017/8/29.
// Copyright © 2017年 Catherine. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override
func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//大小是默认的因此只有前两个位置参数有作用
let myswitch :
UISwitch = UISwitch(frame:
CGRect(x: 100, y:
100, width: 100, height:
100))
//进行属性自定义设置
//设置滑块的颜色
myswitch.thumbTintColor =
UIColor.red
//设置开关开启的颜色
myswitch.onTintColor =
UIColor.blue
//设置关闭开关的渲染颜色(边框的颜色、切换--即点击时的背景色)
myswitch.tintColor =
UIColor.purple
//添加事件
myswitch.addTarget(self, action:
#selector(switchClick(swi:)), for:UIControlEvents.valueChanged
)//检测有值的变化
self.view.addSubview(myswitch)
}
func switchClick(swi:UISwitch){
if swi.isOn{
self.view.backgroundColor =
UIColor.gray
}else{
self.view.backgroundColor =
UIC
4000
olor.white
}
}
override
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//
// Created by Catherine on 2017/8/29.
// Copyright © 2017年 Catherine. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override
func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//大小是默认的因此只有前两个位置参数有作用
let myswitch :
UISwitch = UISwitch(frame:
CGRect(x: 100, y:
100, width: 100, height:
100))
//进行属性自定义设置
//设置滑块的颜色
myswitch.thumbTintColor =
UIColor.red
//设置开关开启的颜色
myswitch.onTintColor =
UIColor.blue
//设置关闭开关的渲染颜色(边框的颜色、切换--即点击时的背景色)
myswitch.tintColor =
UIColor.purple
//添加事件
myswitch.addTarget(self, action:
#selector(switchClick(swi:)), for:UIControlEvents.valueChanged
)//检测有值的变化
self.view.addSubview(myswitch)
}
func switchClick(swi:UISwitch){
if swi.isOn{
self.view.backgroundColor =
UIColor.gray
}else{
self.view.backgroundColor =
UIC
4000
olor.white
}
}
override
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
相关文章推荐
- UI控件 UISwitch 设置默认为开,添加事件
- iOS开发-UI控件:UISwitch控件两种使用方法和监听
- Android学习-常见的UI控件 监听按钮的点击事件
- UI控件的事件监听
- iOS学习之UISwitch控件两种使用方法和监听
- UI控件监听
- Android实战简易教程-第四枪(ScrollView和HorizontalScrollView动态添加控件并提供事件监听)
- Unity游戏UI框架(八):监听事件系统
- android各种控件的事件监听及举例
- iOS:触摸控件UITouch、事件类UIEvent
- UI事件监听的击穿
- UGUI研究院之控件以及按钮的监听事件系统
- ExtJs内的Ext.form.Panel中datefield控件选择日期过后的事件监听select以及比较两个时间的大小
- android中如果activity中应用fragementlayout布局文件,如何给其中的控件添加事件监听。
- 控件的监听事件。
- 背水一战 Windows 10 (69) - 控件(控件基类): UIElement - Manipulate 手势处理, 路由事件的注册, 路由事件的冒泡, 命中测试的可见性
- 手指对控件的按下,放了,背景颜色改变的监听事件
- IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- 非专业码农 JAVA学习笔记 用户图形界面设计与实现-所有控件的监听事件
- 【WPF】监听WPF的WebBrowser控件弹出新窗口的事件