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)
                //.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 RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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.