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)
}
}
SwiftUI โฉ Views and Controls โฉ TextField โฉ
Last updated