textField.style(_:)

// ๐ŸŒ€ TextField + .style()
extension TextField {
    public func style<S>(_ style: S) -> some View where S: TextFieldStyle {
        textFieldStyle(style)
    }
}

// content view
struct ContentView: View {
    @State private var text = "hello"
    var body: some View {
        VStack {
            TextField("hello", text: $text)
                // โญ๏ธ TextField ๅฏไฝฟ็”จ custom method๏ผŒไฝฟ่ชžๆ„ๆ›ด็ฐกๆฝ”
                .style(.plain)
            TextField("hello", text: $text)
        }
        // โญ๏ธ parent view ไฝฟ็”จ .textFieldStyle() ๆ‰ไธๆœƒๅคฑๅŽป contextim
        .textFieldStyle(.roundedBorder)
    }
}

Last updated