如何重命名文本字段占位符

时间:2016-09-09 07:19:03

标签: ios swift uitextfield

我正在使用SCLAlertView,如果用户没有在文本字段输入任何输入,我会重命名文本字段占位符。

func reloadAlertView(msg : String){
        // Create custom Appearance Configuration
        let appearance = SCLAlertView.SCLAppearance(
            kTitleFont: UIFont(name: "Play", size: 14)!,
            kTextFont: UIFont(name: "Play", size: 14)!,
            kButtonFont: UIFont(name: "Play", size: 14)!,
            showCircularIcon: false
        )
        let alert = SCLAlertView(appearance:appearance)
        email = alert.addTextField("Enter email")
        email.text = tempEmail
        alert.addButton("Submit", target: self, selector: #selector(LoginViewController.forgotPasswordBtnPressed))
        alert.showEdit("Forgot Password", subTitle: msg, colorStyle: 0xFF0000, closeButtonTitle : "Close")         
    }

    func forgotPasswordBtnPressed(){

        let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"

        _ = NSPredicate(format:"SELF MATCHES %@", emailRegEx)

        if email.text == ""{
            reloadAlertView("Please fill all field")
        }else{
            validationSuccessful()
        }     
    }

我想重命名文本字段而不是使用此

email = alert.addTextField("Enter email")

当用户输入空格并单击“提交”时

email = alert.addTextField("Please fill this")

1 个答案:

答案 0 :(得分:0)

我可以通过调用与第一个语法相同的语法来重命名字段

if email.text == ""{
            let appearance = SCLAlertView.SCLAppearance(
                kTitleFont: UIFont(name: "Play", size: 14)!,
                kTextFont: UIFont(name: "Play", size: 14)!,
                kButtonFont: UIFont(name: "Play", size: 14)!,
                showCircularIcon: false
            )
            let alert = SCLAlertView(appearance:appearance)
            email = alert.addTextField("You maybe forget this")
            email.text = tempEmail
            alert.addButton("Submit", target: self, selector: #selector(LoginViewController.forgotPasswordBtnPressed))
            alert.showEdit("Forgot Password", subTitle: "Please fill all field", colorStyle: 0xFF0000, closeButtonTitle : "Close")
        }

还有一个问题我怎样才能将字符串重命名为redColor?

email = alert.addTextField("You maybe forget this")
email.textColor = UIColor.redColor()