IOS颜色选择器
UIColorWell
-
UIColorWell是一个继承UIControl的视图,它不能调整大小和UISwitch类似,大小大约是44*44。点击可弹出一个选择颜色的弹窗
-
因为是继承UIControl所以可以添加UIControlEventValueChanged类型的Event事件去监听颜色改变
/// Sets the selected color on the color picker and is updated when the user changes the selection.
/// Does support KVO and does send `UIControlEventValueChanged`.
open var selectedColor: UIColor?
UIColorPickerViewController
-
UIColorPickerViewController是一个继承UIViewController的视图控制器,相比于UIColorWell,它支持协议委托去监听颜色的改变和完成两个状态,iOS15时还会监听颜色变化的持续状态
-
选择颜色完成
func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
print("colorPickerViewControllerDidFinish")
}
- 选择颜色改变
func colorPickerViewController(_ viewController: UIColorPickerViewController, didSelect color: UIColor, continuously: Bool) {
print("选择了颜色:\(color)")
}
PS
标签:颜色,color,IOS,UIColorPickerViewController,选择器,UIColorWell,监听 From: https://www.cnblogs.com/r1cardo/p/17289315.html点击UIColorWell弹出的颜色选择器其实和我们自己弹出UIColorPickerViewController是一样的
UIColorPickerViewController监听完成状态其实只能监听到点击关闭按钮,如果手动将底部弹窗滑下去是监听不到的