NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.