textFile 限制 输入 字数 代码

来源:互联网 发布:淘宝网小饰品店 编辑:程序博客网 时间:2024/05/16 18:38

可以实现textFile的代理方法,并在代理方法中做一下处理

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string // return NO to not change text

{

//原文地址:http://blog.csdn.net/diyagoanyhacker/article/details/7045416

//作者:禚来强

//email:zhuolaiqiang@gmail.com

//转帖请保留

    if (textField == _fpdmTextFile)

    {

        NSString *fpdm = [textField.textstringByReplacingCharactersInRange: rangewithString:@""];

        fpdm = [fpdm stringByAppendingString: string];

        NSInteger countOfFpdm = [fpdm length];

        if (countOfFpdm > 12)

        {

            return  NO;

        }

return YES;

}

原创粉丝点击