如何在我的 iOS 应用程序中获得这种拾色器视图?
How can I get this kind of Color Picker View in my iOS app?
我想在我的应用程序中实现一个 ColorPickerView Controller
,如图所示。
但是我不知道这个圆形元素叫什么,我可以把那个物体变大吗?
我遇到过一个 ColorPickerViewController,它以模态方式呈现为一个完整的另一个场景,但此时此刻,我想实现一个颜色选择器 一点 window无需打开新的 window。
请告诉我如何实现它。
我认为如果不以模式打开它是不可能的。即UIKit中的UIColorPickerViewController,或者SwiftUI中的ColorPicker。在 iOS 14 中看起来像这样。
在 iPadOS 14 中它看起来像这样
在SwiftUI中可以这样创建:
struct ContentView: View {
@State var color = Color(.blue)
var body: some View {
ColorPicker("Color", selection: $color)
.padding(.horizontal, 150)
}
}
在UI套件中是这样的
// Initializing Color Picker
let picker = UIColorPickerViewController()
// Setting the Initial Color of the Picker
picker.selectedColor = self.view.backgroundColor!
// Setting Delegate
picker.delegate = self
// Presenting the Color Picker
self.present(picker, animated: true, completion: nil)
有关更多信息,您可以查看这些网站:
现在另外,如果你真的想要它在一点点 window,你可以使用 PopOver 并创建你自己的颜色选择器,这有点工作,但应该不会太难。
以下资源可能对您有所帮助:
在按钮操作上,使用以下代码。
@IBAction func colorPickerTapped(_ sender: UIButton) {
let colorPickerVC = UIColorPickerViewController()
colorPickerVC.modalPresentationStyle = .popover
colorPickerVC.modalTransitionStyle = .crossDissolve
present(colorPickerVC, animated: true)
let popOverVC = colorPickerVC.popoverPresentationController
popOverVC?.sourceView = sender
colorPickerVC.delegate = self
}
我想在我的应用程序中实现一个 ColorPickerView Controller
,如图所示。
但是我不知道这个圆形元素叫什么,我可以把那个物体变大吗?
我遇到过一个 ColorPickerViewController,它以模态方式呈现为一个完整的另一个场景,但此时此刻,我想实现一个颜色选择器 一点 window无需打开新的 window。 请告诉我如何实现它。
我认为如果不以模式打开它是不可能的。即UIKit中的UIColorPickerViewController,或者SwiftUI中的ColorPicker。在 iOS 14 中看起来像这样。
在 iPadOS 14 中它看起来像这样
在SwiftUI中可以这样创建:
struct ContentView: View {
@State var color = Color(.blue)
var body: some View {
ColorPicker("Color", selection: $color)
.padding(.horizontal, 150)
}
}
在UI套件中是这样的
// Initializing Color Picker
let picker = UIColorPickerViewController()
// Setting the Initial Color of the Picker
picker.selectedColor = self.view.backgroundColor!
// Setting Delegate
picker.delegate = self
// Presenting the Color Picker
self.present(picker, animated: true, completion: nil)
有关更多信息,您可以查看这些网站:
现在另外,如果你真的想要它在一点点 window,你可以使用 PopOver 并创建你自己的颜色选择器,这有点工作,但应该不会太难。
以下资源可能对您有所帮助:
在按钮操作上,使用以下代码。
@IBAction func colorPickerTapped(_ sender: UIButton) {
let colorPickerVC = UIColorPickerViewController()
colorPickerVC.modalPresentationStyle = .popover
colorPickerVC.modalTransitionStyle = .crossDissolve
present(colorPickerVC, animated: true)
let popOverVC = colorPickerVC.popoverPresentationController
popOverVC?.sourceView = sender
colorPickerVC.delegate = self
}