How can I get this kind of Color Picker View in my iOS app?

3.2k Views Asked by At

I would like to implement a ColorPickerView Controller in my app like this in the picture. But I don't know what this circle element is called and may I make that object bigger? enter image description here

I have encountered a ColorPickerViewController that is presented modally as a complete another scene but at this moment, I would like to implement a color picker as a little window without opening a new window. Please, tell me how I can implement this.

2

There are 2 best solutions below

4
Jonathan On BEST ANSWER

I don't think it's possible to do that without opening it modally. That is the UIColorPickerViewController in UIKit, or ColorPicker in SwiftUI. It looks like this in iOS 14. iOS 14 ColorPicker

and in iPadOS 14 it would look like this iPadOS 14 ColorPicker

In SwiftUI it can be created like this:

struct ContentView: View {

@State var color = Color(.blue)

var body: some View {
        ColorPicker("Color", selection: $color)
            .padding(.horizontal, 150)
}

}

and in UIKit it is like this

// 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)

For more information you can take a look at these websites:

Now Additionally, if you really want it to be in a little window, you can use a PopOver and create your own color picker, it is a bit of work but shouldn't be too hard.

Here are some resources that might help you:

0
Dayanithi Natarajan On

On button action, use the below code.

@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

}