skip to Main Content

I want to change the label color of SwiftUI Picker from blue to black, tried .foregroundColor(.black) and .tint(.black), but the color remains blue.

@State var privacy = Privacy.open
enum Privacy: String, CaseIterable, Identifiable {
    case open = "Open"
    case closed = "Closed"
    var id: String {
        self.rawValue
    }
}
    
var body: some View {
    Picker("privacy", selection: $privacy) {
        ForEach(Privacy.allCases) { value in
            Text(value.rawValue)
                .tag(value)
        }
    }
    .pickerStyle(.menu)
    .tint(.black)
    .foregroundColor(.black)
}

2

Answers


  1. I tried foregroundStyle and accentColor and only accentColor worked. It does have a future deprecation warning, but you should be able to use it for now.

    .accentColor(.orange)
    
    Login or Signup to reply.
  2. As the other user has mentioned, .accentColor(.orange) works, but has a depreciation warning.

    Using .tint(.orange) does not have this warning and will color the picker text.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search