iOS swift 限制TextField TextView输入长度(14个字符)

func textField(textField:UITextField, shouldChangeCharactersInRange range:NSRange, replacementString string:String) ->Bool{

if(range.length==1&& string.characters.count==0) {

return true

}

elseif(textField.text?.characters.count>=14) {

textField.text= textField.text?.substringToIndex((textField.text?.startIndex.advancedBy(14))!)

return false

}

return true

}

你可能感兴趣的:(iOS swift 限制TextField TextView输入长度(14个字符))