I have a picker in my app that displays the currently picked option as its label. However, I can’t seem to figure out how to change the font used by the picker for its label and for displaying all the picker options. I would also like to put an icon in front of the text of the picker that’s part of the picker button but doesn’t change as the text does so that a user could click both the text and the icon for the picker to appear.
Here’s the code I am using for my picker:
var fylker = ["Norge", "Akershus", "Agder", "Buskerud", "Finnmark", "Innlandet", "Møre og Romsdal", "Nordland", "Oslo", "Østfold", "Rogaland", "Troms", "Trøndelag", "Vestfold og Telemark", "Vestland"]
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: .self) {
Text($0)
}
}
I’ve already tried things like:
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: .self) {
Text($0).font(.custom("Custom-Bold", size: 34))
}
}
and
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: .self) {
HStack {
Image(systemName: "chevron.forward.circle")
Text($0)
}
}
}
to no avail
Any ideas?
Thanks!
3
Answers
from what i understand i think you could try to use a font modifier to add your custom font and add image inside HStack so they are beside each other like that
also if you mean to add the image beside the picker so they seemed as a button picker you can do that
try this approach to set the font used by the
Picker
:This does not work with pickerStyle:
automatic
,menu
andsegmented