iOS 14
新增了一个UIColorPickerViewController
控制器用来选择颜色
这样我们就可以愉快的在App内改变想要的颜色了,实现代码也超级的简单
import UIKit
class ColorViewController: UIColorPickerViewController {
var selectColorBlock: ((UIColor) -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.delegate = self
}
}
extension ColorViewController: UIColorPickerViewControllerDelegate {
func colorPickerViewControllerDidSelectColor(_ viewController: UIColorPickerViewController) {
print(viewController.selectedColor)
}
func colorPickerViewController(_ viewController: UIColorPickerViewController, didSelect color: UIColor, continuously: Bool) {
selectColorBlock?(color)
}
func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
print(viewController.selectedColor)
}
}
let colorVC = ColorViewController()
colorVC.selectColorBlock = { [weak self] cor in
self?.view.backgroundColor = cor
}
self.present(colorVC, animated: true)
网友评论