Chapter 8: Controls and User Input -> Styling the TextField

In page 169, you said " At the time of writing, the latter option is not well-documented, and the protocol itself has an empty implementation."
Yes, but the form is:

public struct MyTextFieldStyle : TextFieldStyle {
    public func _body(configuration: TextField<Self._Label>) -> some View {
        configuration
            .padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
            .background(Color.white)
            .overlay(
                RoundedRectangle(cornerRadius: 8)
                    .stroke(lineWidth: 2)
                    .foregroundColor(.blue)
            )
            .shadow(color: Color.gray.opacity(0.4),
                    radius: 3, x: 1, y: 2)
            .padding([.leading, .trailing], 20)
    }
}

as in the sample:

using:

TextField("Type your name...", text: $name)
    .textFieldStyle(MyTextFieldStyle())

That is a good observation and good you clarified it here.

Thanks @carlosypunto74, I’ll check that soon

Hi @carlosypunto74, just to let you know that we’re working on a book update, which will be released in the upcoming weeks - thanks for showing me how to use TextFieldStyle, I’ll include it in the update. Thank you very much

1 Like

@carlosypunto74 @james.brownn732 Please check out the updated version of the book when you get a chance:

https://store.raywenderlich.com/products/swiftui-by-tutorials

I hope it helps!