ios - UITextfield limit The Chinese characters length -
#define maxlength 12 - (bool)textfield:(uitextfield *) textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { if (textfield.tag == nicknmae_tag) { nsuinteger oldlength = [textfield.text length]; nsuinteger replacementlength = [string length]; nsuinteger rangelength = range.length; nsuinteger newlength = oldlength - rangelength + replacementlength; bool returnkey = [string rangeofstring: @"\n"].location != nsnotfound; homecoming newlength <= maxlength || returnkey; } homecoming yes; }
i used methods limit length of textfield. worked when iputing usual characters. unfortunately, doesn't work when inputing chinese characters.
when inputing languages uses input method, input of pinyin makes -textfield: shouldchangecharactersinrange:replacementstring called, , when select chinese characters, phone call method occurs, sadly, can't distinguish whether method called inputing pinyin or changing pinyin chinese.
so it's improve allow user input more characters limit, not allowing user submit input. can see how weibo when user input there feed.
i'v found solution: can utilize @property markedtextrange, can if there pinyin waiting chinese character selection, if there any, don't limit input string length, , 1 time user turn pinyin chinese character, can truncate chinese string upon limit.
ios uitextfield
No comments:
Post a Comment