textField.placeholder = @"请输入标签(最多输入3个汉字)";
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldEditChanged:) name:UITextFieldTextDidChangeNotification object:textField];
-(void)textFieldEditChanged:(NSNotification *)obj{
UITextField *textField = (UITextField *)obj.object;
NSString *toBeString = textField.text;
NSString *lang = [[UIApplication sharedApplication]textInputMode].primaryLanguage;
if ([lang isEqualToString:@"zh-Hans"]) {
UITextRange *selectedRange = [textField markedTextRange];
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
if (!position) {
if (toBeString.length>TagLength) {
textField.text = [toBeString substringToIndex:TagLength];
}
}
else{
}
}
else{
if (toBeString.length > TagLength) {
textField.text = [toBeString substringToIndex:TagLength];
}
}
}