限定UITextField输入的字数

来源:互联网 发布:小偷公司知乎 编辑:程序博客网 时间:2024/04/30 02:45

// 限定textField输入的字数

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{

    int  texttNum;

    //计算剩下多少文字可以输入

    if(range.location>=4)

    {

        return NO;

    }

    else

    {

        NSString  * str=verificationField.text;

        int   str=[nsTextContent length];

        texttNum=4-existTextNum;

        return YES;

    }  

    

}

原创粉丝点击