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 RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.