代码如下:

static constNSInteger Max_Character_Num =4;

    - (IBAction)onTextFieldEditingChanged:(id)sender   
    {   
        NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage];   
        if ([lang isEqualToString:@"zh-Hans"]) {   
            UITextRange *selectedRange = [self.tagNameTextField markedTextRange];   
            UITextPosition *position = [self.tagNameTextField positionFromPosition:selectedRange.start offset:0];   
            if (!position) {   
                if (self.tagNameTextField.text.length > Max_Character_Num) {   
                    self.tagNameTextField.text = [self.tagNameTextField.text substringFrom:0 to:Max_Character_Num];   
                }   
            }   
        }else{   
            if (self.tagNameTextField.text.length > Max_Character_Num) {   
                self.tagNameTextField.text = [self.tagNameTextField.text substringFrom:0 to:Max_Character_Num];   
            }   
        }   
    }  
来自:http://blog.csdn.net/wang_lichun/article/details/45251217
发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

fmdb常用操作代码详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。