How to Change Picker Text Color In SwiftUI

I try to change picker text color but, it does not work.

As you see, "City" and "District"'s color are blue but, I'd like to make them white. I have tried below codes but, they do not work.

Do you know any methods for that ?

Picker("İl", selection: $selectedCity) {
      ForEach(turkishCities, id: \.self) { city in
         Text(city)
           .foregroundColor(.white)
      }
}
Picker("İlçe", selection: $selectedDistrict) {
    ForEach(cityDistricts[selectedCity] ?? [], id: \.self) { district in
        Text(district)
            .foregroundColor(Color.white)
    }
}
.onAppear {
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.white], for: .normal)
}

Thank you in advance.

Answered by Claude31 in 769235022

Using accentColor should do it:

Picker("İl", selection: $selectedCity) {
      ForEach(turkishCities, id: \.self) { city in
         Text(city)
      }
} 
 .accentColor(.red)

A small example to show to select between User1, User2, User3:

            Picker("User", selection: $selectedUser) {
                ForEach(users, id: \.self) { user in
                    Text(user)
                        .tag(user)
                }
            }
            .accentColor(.red)

With accentColor:

without accentColor:

Note: that does not work If the picker is within a form.

Accepted Answer

Using accentColor should do it:

Picker("İl", selection: $selectedCity) {
      ForEach(turkishCities, id: \.self) { city in
         Text(city)
      }
} 
 .accentColor(.red)

A small example to show to select between User1, User2, User3:

            Picker("User", selection: $selectedUser) {
                ForEach(users, id: \.self) { user in
                    Text(user)
                        .tag(user)
                }
            }
            .accentColor(.red)

With accentColor:

without accentColor:

Note: that does not work If the picker is within a form.

As @obaytimur proposed, tint seems the way to go. Also, in some cases accentColor doesn't seem to work. I had a quite nested view with the picker inside, and the text color wouldn't change with accentColor. tint worked. Thanks

How to Change Picker Text Color In SwiftUI
 
 
Q