'How to change the Picker menu text size in SwiftUI?
I have a Picker of style Menu and I need to change its text size (the blue text), I tried the .font(.largeTitle) modifier but it didn't work.
enum Privacy: String, Identifiable, CaseIterable {
case open = "Open"
case closed = "Closed"
var id: String { self.rawValue }
}
struct ContentView: View {
@State var selection = Privacy.open
var body: some View {
Picker("Privacy", selection: $selection) {
ForEach(Privacy.allCases) { value in
Text(value.rawValue)
.tag(value)
.font(.largeTitle)
}
}
.font(.largeTitle)
.pickerStyle(.menu)
}
}
Solution 1:[1]
Remove the .menu style and just wrap it in Menu instead, with a custom label:
Menu {
Picker(selection: $selection) {
ForEach(Privacy.allCases) { value in
Text(value.rawValue)
.tag(value)
.font(.largeTitle)
}
} label: {}
} label: {
Text("Privacy")
.font(.largeTitle)
}
Solution 2:[2]
If someone needs to show selected value as label (instead of static text) in this scenario, the following variant can be used
Tested with Xcode 13.2 / iOS 15.2
Menu {
Picker(selection: $selection) {
ForEach(Privacy.allCases) { value in
Text(value.rawValue)
.tag(value)
}
} label: {}
} label: {
Text(selection.rawValue)
.font(.largeTitle)
}.id(selection)
Solution 3:[3]
I found that the Menu { Picker() {} } trick did broken things on Mac (nests the proper menu inside a single item menu). But this slight mod is so far working cleanly across iPhone, iPad, and Mac:
Menu {
ForEach(RowLabelType.allCases, id: \.self) { type in
Button {
todayTabRowLabels = type
} label: {
Text(type.displayString)
}
}
} label: {
Text(todayTabRowLabels.displayString)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | George |
| Solution 2 | |
| Solution 3 | sobri |


