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.
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.