HTTP请求SwiftUI后更改TextField边框颜色

时间:2020-03-06 13:44:20

标签: ios xcode swiftui textfield

问题如下: 我有几个文本字段,如果字段为空并且用户尝试向服务器发送请求(例如,登录或注册),我想更改边框颜色。我为所有TextField编写了扩展名:

extension View {
    public func addTextFieldOptions(colorBorder: Color) -> some View {

    return font(.custom("Avenir", size: 15))
    .padding(EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16))
    .background(Color(.white))
    .cornerRadius(8).overlay(
    RoundedRectangle(cornerRadius: 6)
        .stroke(colorBorder, lineWidth: 2))
    }
}

现在我们正在创建一个TextField:

TextField("Email", text: $email).addTextFieldOptions(colorBorder: defaultColorBorder)

现在,在我们在字段中输入数据(或未在字段中输入数据)之后,我在HTTP请求中遇到了这种情况!这是在我们发送请求后触发的!!! :

(email.isEmpty == true) {
    print("email IS EMPTY")
      // HERE          
  }

实际上,现在的问题本身就是:如何触发该条件,以便在触发此条件时,TextField边框的颜色发生变化?

0 个答案:

没有答案