WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

How to add an attribute to TextField?

Forums > SwiftUI

Good afternoon. Tell me how to add an attribute to the textField?

    var body: some View {
        VStack(alignment: .center) {
            TextField("\(placeholder)", text: $title)
                .frame(width: 264, height: 55, alignment: .center)
                .keyboardType(.numberPad)
                //.font(Font.custom("SNS Medium", size: 33))
                .font(Font.custom("SF Pro Display", size: 44))
                .multilineTextAlignment(.center)
                .background(Color.white)
                .overlay(
                    RoundedRectangle(cornerRadius: 10)
                            .stroke()
                )
        }
    }

1      

Steven commands:

Tell me how to add an attribute to the textField

I feel there is more to your command your request.

You've already added six modifiers to your TextField, background colors, frame, keyboard attributes. Nice job!

What is missing here? Please, give us a couple of more clues!

1      

Good day, @Obelix. I am I don't know how to add kerning.

  TextField("\(placeholder)", text: $title)
                .kerning(2.0) - error

1      

Kerning can only be applied to Text, not TextField. If you want a text field with kerning, you have to roll your own using UIViewRepresentable.

1      

Know how to apply it.

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

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

Reply to this topic…

You need to create an account or log in to reply.

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.