Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/65861029/how-can-i-get-this-kind-of-color-picker-view-in-my-ios-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...