如何实时查看textfield是否为空?

时间:2018-02-06 13:39:58

标签: ios swift xcode uibutton

当用户填写了两个UITextField时,我正在尝试更改我的UIButton的外观,但是我无法通过while循环。这是我的代码:

override func viewDidLoad() {
        super.viewDidLoad()
        FirstNameTextField.becomeFirstResponder()
        FirstNameTextField.setBottomBorder()
        LastNameTextField.setBottomBorder()
        SignUpAndAccept.layer.cornerRadius = 10
        SignUpAndAccept.clipsToBounds = true
        SignUpAndAccept.isEnabled = false
        self.navigationController?.navigationBar.isHidden = true
        test()
            }


        func test(){
        repeat {
            if ((LastNameTextField.text?.isEmpty ?? true) && (FirstNameTextField.text?.isEmpty ?? true)){
                SignUpAndAccept.backgroundColor = UIColor.gray
                SignUpAndAccept.isEnabled = false
                }
            else if((LastNameTextField.text?.isEmpty ?? false) && (FirstNameTextField.text?.isEmpty ?? false)) {
                SignUpAndAccept.backgroundColor = UIColor.purple
                SignUpAndAccept.isEnabled = true
            }
        }while (SignUpAndAccept.isEnabled == false)
}

0 个答案:

没有答案