我像这样更改了 TextField 样式:
TextField("Test", text: $name).textFieldStyle(CustomTextFieldStyle())
Run Code Online (Sandbox Code Playgroud)
现在我希望它在用户点击它时改变样式。
我的 CustomTextFieldStyle 定义为:
public struct CustomTextFieldStyle : TextFieldStyle {
public func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.font(.callout)
.padding(10)
.background(
RoundedRectangle(cornerRadius: 4)
.strokeBorder(SBGreen, lineWidth: 2))
}
}
Run Code Online (Sandbox Code Playgroud)