-(void)textfilededitchanged: (nsnotification *)obj{
Uitextfield*TextField= (Uitextfield*)Obj.Object
NSString*Tobestring=TextField.Text
NSString*Lang=[[UitextinputmodeCurrentinputmode]Primarylanguage];Keyboard Input Mode
If([LangIsequaltostring:@ "Zh-hans"]){Simplified Chinese input, including simplified pinyin, fitness wubi, simplified handwriting
Uitextrange*Selectedrange=[TextFieldMarkedtextrange];
Get highlighted parts
Uitextposition*Position=[TextFieldPositionfromposition:Selectedrange.StartOffset0];
Word count and limit the words you have entered without highlighting the selected words
If!Position{
IfTobestring.Length>Kmaxlength){
TextField.Text=[TobestringSubstringtoindex:Kmaxlength];
}
}
There is a highlighted string, the text is temporarily not counted and limited
Else{
}
}
Direct statistical restrictions other than Chinese input method, regardless of other languages
Else{
if (tobestring. Length > kmaxlength) {
textfield text= [tobestring substringtoindex:kmaxlength];
"
"
/span> -(void) Dealloc{
[[nsnotificationcenterdefaultcenter]removeobserver:Self
Name:@ "Uitextfieldtextdidchangenotification"
object:_albumnametextfield];
}
IOS textfield input length limit kanji invalid