1

Is there a way of tapping another view/object and open the picker (with a onTapGesture for instance? Apparently the only way is tapping on the small circle :|

I would like to tap the violet object and have the picker open.

I appreciate any help, thanks !

VStack {
    ColorPicker("Color picker :", selection: $selectedColor, supportsOpacity: false)
        .padding()
    Rectangle()
        .foregroundColor(selectedColor)
        .onTapGesture {
            // open picker :)
        }
}
George
  • 25,988
  • 10
  • 79
  • 133
neovision
  • 31
  • 5
  • I answered same question in the past in this link! https://stackoverflow.com/a/67145239/14998134 – ios coder Sep 03 '21 at 02:21
  • thanks @swiftPunk for your answer. it's not exactly the way i was interest to implement, because i would like to hide le little color circle and click another element to open the picker. but it was worth to learn something else ... thanks! – neovision Sep 05 '21 at 15:03
  • I believe you could not use it, because it is exactly what you are searching. – ios coder Sep 05 '21 at 15:14

1 Answers1

0

It can be done, but you have to create your own instance of UIColorPickerViewController and then activate it with SwiftUI.

I tried a few things using only SwiftUI and at least I couldn't do it

Zapata
  • 21
  • 3
  • Thanks @Zapata for your answer. That was my fear, the need to implement UIKit stuff on a shiny SwiftUI code. Inevitable ... – neovision Sep 05 '21 at 15:07