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)
                //.font(Font.custom("SNS Medium", size: 33))
                .font(Font.custom("SF Pro Display", size: 44))
                    RoundedRectangle(cornerRadius: 10)


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!


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

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


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.


Know how to apply it.


Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

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.