我如何在iPad上制作类似于颜色轮、颜色选择器或色调选择器的东西?
这是一个与我想要的类似的颜色选择器的示例图片。
@所有人,提前感谢。
我如何在iPad上制作类似于颜色轮、颜色选择器或色调选择器的东西?
这是一个与我想要的类似的颜色选择器的示例图片。
@所有人,提前感谢。
这篇文章可能会对你有所帮助。一个简单的选色方式是获取你提供的图片中某个像素的颜色。这个 Github 项目还提供了完整的颜色选择器源代码。
UIColorPickerViewController
,而且非常简单明了。let picker = UIColorPickerViewController()
picker.delegate = self
present(picker, animated: true, completion: nil)
我在draw(_ rect: CGRect)中创建了一个彩色轮的扇形。点击这里查看。
这个视图基于以下代码行:
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else {
return
}
// Choice width and x position of a rect where will be placed you picker
for x in stride(from: bounds.midX - bounds.height, to: bounds.midX + bounds.height, by: elementSize) {
// Choice height and y position of the rect
for y in stride(from: 0, to: rect.height, by: elementSize) {
// Select color for a point
context.setFillColor(colorFor(x: x, y: y))
// Select color for the point with elementSize which we declare and init as class property
context.fill(CGRect(x: x, y: y, width: elementSize, height: elementSize))
}
}
}