zoukankan      html  css  js  c++  java
  • uitextFiled字数输入限制

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

        if (self.type == YXModifyTrueLoveInputTypeNick) {

            NSLog(@"%ld",[self countTheStrLength:[textField.text stringByReplacingCharactersInRange:range withString:string]]);

            NSInteger textLength = [self countTheStrLength:[textField.text stringByReplacingCharactersInRange:range withString:string]];

            if (textLength > 4 && string.length > 0) {

                return NO;

            } else {

                self.textLabel.text = [NSString stringWithFormat:@"还可以输入%d个字符",(int)MAX(4 - textLength, 0)];

            }

        }

        return YES;

    }

    - ( NSInteger )countTheStrLength:( NSString *)strtemp {

        NSInteger strlength = 0 ;

        char * p = ( char *)[strtemp cStringUsingEncoding : NSUnicodeStringEncoding ];

        for ( int i= 0 ; i<[strtemp lengthOfBytesUsingEncoding : NSUnicodeStringEncoding ] ;i++) {

            if (*p) {

                p++;

                strlength++;

            }else {

                p++;

            }

        }

        return (strlength+ 1 )/ 2 ;

    }

  • 相关阅读:
    Stl源码剖析读书笔记之Alloc细节
    Lua热更系统
    Linux C++线程池
    linux sort,uniq,cut,wc.
    (转)Linux grep
    用LogParser分析IIS请求压力
    (转)MySQL主从复制的常见拓扑、原理分析以及如何提高主从复制的效率总
    AIS相关资料
    python学习笔记
    (转)MySQL InnoDB修复笔记
  • 原文地址:https://www.cnblogs.com/106dapeng/p/6436757.html
Copyright © 2011-2022 走看看