美文网首页
Swift_UITextField

Swift_UITextField

作者: _杜兜兜_ | 来源:发表于2016-10-10 11:43 被阅读5138次

    1,提示信息

    textField.placeholder = "请输入"
    

    2,密文输入

    textField.secureTextEntry = true
    

    3,不可被输入

    textField.userInteractionEnabled = false
    

    4,限制输入的长度
    调用

           textField.addTarget(self, action: #selector(self.textDidChangeMax(_:)), forControlEvents: UIControlEvents.EditingChanged)
    

    声明方法

        var NumberMax : Int{
            return 11
        }
        func textDidChangeMax(sender:UITextField) {
            let lang = textInputMode?.primaryLanguage
            if lang == "zh-Hans" {
                let range = textField.markedTextRange
                if range == nil {
                    if textField.text?.characters.count >= NumberMax {
                        textField.text = textField.text?.substringToIndex((textField.text?.startIndex.advancedBy(NumberMax))!)
                    }
                }
            }
            else {
                if textField.text?.characters.count >= NumberMax {
                    textField.text = textField.text?.substringToIndex((textField.text?.startIndex.advancedBy(NumberMax))!)
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:Swift_UITextField

          本文链接:https://www.haomeiwen.com/subject/vknmyttx.html