iOS swift 限制TextField TextView输

2016-11-07  本文已影响600人  ali_hilo

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

}

上一篇下一篇

猜你喜欢

热点阅读