13

I want to set a picker button borderless and transparent in SwiftUI on macOS.

I tried using .background(), .border() and .opacity() modifiers on the Picker view. However, I can't change the background to a transparent color using .background(), I can't remove the border using .border(), and I can't find a way to change only the background to transparent using .opacity().

Here is my code for the picker:

Picker(selection: .constant(1), label: EmptyView()) {
    Text("1").tag(1)
    Text("2").tag(2)
}
.scaledToFit()

.constant(1) is a placeholder

Currently the picker looks like this:
Current Picker Look

I want it to look like the pickers in the Contacts app on Mac:
Wanted Picker Look


UPDATE (2019-11-30)

After trying all likely modifiers and functions that are applicable to a Picker, I've determined that there is no solution so far. SwiftUI is incomplete as a replacement for storyboards or XIB as of now.

1 Answers1

0

Try to use .background(.gray .opacity(0.3)) this makes the background color opacity and nothing else,I mean the text will remain the same opacity as before.

Fovu
  • 71
  • 6
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30632282) – CodeChanger Dec 24 '21 at 07:14