Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the Picker menu text size in SwiftUI?

Tags:

ios

swift

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)
    }
}

like image 253
Fawzi Rifai Avatar asked Sep 07 '25 21:09

Fawzi Rifai


2 Answers

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)
}
like image 139
George Avatar answered Sep 09 '25 12:09

George


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

demo

Menu {
    Picker(selection: $selection) {
        ForEach(Privacy.allCases) { value in
            Text(value.rawValue)
                .tag(value)
        }
    } label: {}
} label: {
    Text(selection.rawValue)
        .font(.largeTitle)
}.id(selection)
like image 25
Asperi Avatar answered Sep 09 '25 11:09

Asperi