SwiftUI: Resize ColorPicker on macOS

Viewed 225

I am using a ColorPicker in one of my SwiftUI-based macOS apps. In previous versions of macOS ColorPicker behaved like a Color or Spacer View: It filled all the available space. This behaviour changed — it seems to have a fixed default size now:

enter image description here

How can I change the size of ColorPicker on macOS (SwiftUI)?

  • .frame() modifier has no effect
  • No luck with adjustments within GeometryReader
  • .resizable() has a visual effect but results in a static (not clickable) view
1 Answers

If you want to make it smaller, you can use scaleEffect:

ColorPicker("", selection: .constant(.red))
    .scaleEffect(x: 0.5, y: 0.5)

To make the border square-shaped, use .scaleEffect(x: 0.521739, y: 1).

Related