UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

swiftui - How do you specify a font modifier within a Picker

Forums > SwiftUI

@al484  

Very much a swiftui noob; Can anyone direct me to how to properly apply a .font modifier on the text within a picker? e.g. in this sample code, why are the picker selections not rendered as the text above it?

struct ContentView: View {
    @State var selection: String = "A"

    var body: some View {
        VStack {
            Text(selection).font(.largeTitle).foregroundColor(.red)

            Picker("Picker",
                   selection: $selection,
                   content: {
                        Text("A").tag("A").font(.largeTitle).foregroundColor(.red)
                        Text("B").tag("B").font(.largeTitle).foregroundColor(.red)
                    }
            )

        }
    }
}

I am seeing that application of a PickerStyle only only partially helpful.

.pickerStyle(MenuPickerStyle())   // fomatting ignored...

.pickerStyle(WheelPickerStyle())  // formatting works...

Can MenuPickerStyle() be made to format the Text view?

2      

You could try creating an extension for Picker and / or Text.

Here is an example for Text to give you some ideas - Text extension.

2      

@al484  

Thank you @Greenamberred, while this didn't work here, I can see how useful extension's could be.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.