ios 如何实现在一个js实现输入框搜索联想里相同的字母不能超过三次??

iOS开发一行代码系列:一行搞定输入框优化
iOS8以前,我们设置键盘为UIKeyboardTypeNumberPad类型的,我们就不太容易输入字母或者其他的。
iOS8以后,由于支持了第三方输入法,就算设置键盘为UIKeyboardTypeNumberPad类型的,我们随便切换下就很容易输入其他字母啦。
为了解决这样的问题,我们对InputHelper进行优化,这样以后我们就不用为这样的小问题浪费时间了。
常见的小问题还有,评论字数的限制,如果超过120字可能会做截取或者弹出提示框;或者不能输入空格;或者只能输入英文。
代码如下:
typedef void(^InputHelperDoneBlock)(id);
typedef void(^InputHelperValidationError)(id,NSString*);
typedef NS_ENUM(NSInteger, InputHelperDismissType) {
InputHelperDismissTypeNone = 0,
InputHelperDismissTypeCleanMaskView,
InputHelperDismissTypeTapGusture
typedef NS_ENUM(NSInteger, ValidationType) {
ValidationTypeNone = 0,
//no limit
ValidationTypeNoWhiteSpace,
//no whitespace character
ValidationTypeNumberInt,
//int number only
ValidationTypePhone,
//phone only
ValidationTypeAlphabetAndNumber,
//alphabet and number
@interface InputHelper : NSObject
+ (InputHelper *)sharedInputH
- (void)dismissInputH
//keyboard
- (void)setupInputHelperForView:(UIView *)view withDismissType:(InputHelperDismissType)dismissT
- (void)setupInputHelperForView:(UIView *)view withDismissType:(InputHelperDismissType)dismissType doneBlock:(InputHelperDoneBlock)doneB
//validation
- (void)setupValidationType:(ValidationType)type forInputField:(UIView *)inputF
- (void)limitTextLength:(NSInteger)length forInputField:(UIView *)inputF
@interface NSString (InputHelper)
- (NSString *)trimmedS
#import InputHelper.h
static NSString *kInputHelperTapGusture= @kInputHelperTapG
static NSString *kInputHelperDismissType= @kInputHelperDismissT
static NSInteger tapTag = 2014;
static NSString *kInputHelperRootViewOriginalOriginY = @kInputHelperRootViewOriginalOriginY;
static NSString *kInputHelperRootViewAllInputFieldOriginYDictionary = @kInputHelperRootViewAllInputFieldOriginYD
static NSString *kInputHelperRootViewSortedInputFieldArray = @kInputHelperRootViewSortedInputFieldA
static NSString *kInputHelperDoneBlock = @kInputHelperDoneB
static NSString *kInputHelperValidationType = @kInputHelperValidationT
static NSString *kInputHelperInputFiedlTextLength = @kInputHelperInputFiedlTextL
static NSString *kInputHelperTextLengthLimit = @kInputHelperTextLengthL
static void setAssociatedObjectForKey(UIView *view ,NSString *key,id value){
objc_setAssociatedObject(view, (__bridge
const void *)(key), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
static id getAssociatedObjectForKey(UIView *view ,NSString *key) {
objc_getAssociatedObject(view, (__bridge
const void *)(key));
#define INT_NUMBER_SET
#define PHONE_SET
@^1{1,}\d*$
#define ALPHABET_NUMBER_SET @^[0-9A-Za-z@_.\-]+$
@interface InputHelperTapGusture: UITapGestureRecognizer
@property (assign, nonatomic) NSI
@implementation InputHelperTapGusture
@interface InputHelper ()
@property (strong, nonatomic) UIView *cleanMaskV
@property (strong, nonatomic) UIToolbar *toolBarForCleanMaskV
@property (strong, nonatomic) UIToolbar *toolB
@property (assign, nonatomic) CGSize keyboardS
@property (assign, nonatomic) CGFloat perMoveDistanceForInputF
@property (assign, nonatomic) CGRect defaultToolBarF
@property (assign, nonatomic) CGRect defaultMaskViewF
@property (assign, nonatomic) CGRect toolBarFrameInMaskV
//current root view
@property (weak, nonatomic) UIView *currentRootV
@implementation InputHelper
- (UIToolbar *)createInputHelperToolBar{
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:_defaultToolBarFrame];
toolBar.barStyle = UIBarStyleBlackT
UIBarButtonItem *btnPrevious = [[UIBarButtonItem alloc]initWithTitle:@上一项 style:UIBarButtonItemStyleDone target:self action:@selector(didClickButtonPrevious)];
UIBarButtonItem *btnNext = [[UIBarButtonItem alloc]initWithTitle:@下一项 style:UIBarButtonItemStyleDone target:self action:@selector(didClickButtonNext)];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *btnDown = [[UIBarButtonItem alloc]initWithTitle:@完成 style:UIBarButtonItemStyleDone target:self action:@selector(didClickButtonDone)];
[toolBar setItems:[[NSArray alloc]initWithObjects:btnPrevious,btnNext,spaceItem,btnDown, nil]];
return toolB
- (void)initilize
_defaultToolBarFrame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 40);
_defaultMaskViewFrame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
_toolBarFrameInMaskView = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 40, [[UIScreen mainScreen] bounds].size.width, 40);
_perMoveDistanceForInputField = 40;
_keyboardSize = CGSizeMake(320, 256);
//tool bar
self.toolBar = [self createInputHelperToolBar];
self.toolBarForCleanMaskView = [self createInputHelperToolBar];
_toolBarForCleanMaskView.frame = _toolBarFrameInMaskV
//tap mask view
_cleanMaskView = [[UIView alloc]initWithFrame:_defaultMaskViewFrame];
_cleanMaskView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didClickButtonDone)];
[_cleanMaskView addGestureRecognizer:tap];
[_cleanMaskView addSubview:_toolBarForCleanMaskView];
NSNotificationCenter *notifCenter = [NSNotificationCenter defaultCenter];
[notifCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[notifCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateFirstResponder:) name:UITextFieldTextDidBeginEditingNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateFirstResponder:) name:UITextFieldTextDidEndEditingNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateFirstResponder:) name:UITextViewTextDidBeginEditingNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateFirstResponder:) name:UITextViewTextDidEndEditingNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateInputFieldText:) name:UITextFieldTextDidChangeNotification object:nil];
[notifCenter addObserver:self selector:@selector(updateInputFieldText:) name:UITextViewTextDidChangeNotification object:nil];
- (instancetype)init{
self = [super init];
if (self) {
[self initilize];
+ (InputHelper *)sharedInputHelper{
static InputHelper *
static dispatch_once_t onceT
dispatch_once(&onceToken, ^{
instance = [[InputHelper alloc]init];
#pragma mark - APIs
- (void)setupInputHelperForView:(UIView *)view withDismissType:(InputHelperDismissType)dismissType doneBlock:(InputHelperDoneBlock)doneBlock{
self.currentRootView =
setAssociatedObjectForKey(view, kInputHelperDismissType, @(dismissType));
NSMutableDictionary *dic= [NSMutableDictionary new];
setAssociatedObjectForKey(view, kInputHelperRootViewAllInputFieldOriginYDictionary, dic);
NSMutableArray *array = [NSMutableArray new];
setAssociatedObjectForKey(view, kInputHelperRootViewSortedInputFieldArray, array);
objc_setAssociatedObject(view, (__bridge
const void *)(kInputHelperDoneBlock), doneBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
[self checkInputFieldInView:view withViewOriginY:view.frame.origin.y];
NSArray *keys = [getAssociatedObjectForKey(view, kInputHelperRootViewAllInputFieldOriginYDictionary) allKeys];
if (keys.count == 0) {
NSArray *sortedOriginYArray = [keys sortedArrayUsingComparator:^(id obj1, id obj2){
if ([obj1 compare:obj2] == NSOrderedDescending){
return NSOrderedD
if ([obj1 compare:obj2] == NSOrderedAscending){
return NSOrderedA
return NSOrderedS
UIView *inputAccessoryView = _toolB
if (dismissType == InputHelperDismissTypeNone) {
_toolBar.frame = _defaultToolBarF
} else if (dismissType == InputHelperDismissTypeCleanMaskView){
inputAccessoryView = _cleanMaskV
} else if (dismissType == InputHelperDismissTypeTapGusture){
setAssociatedObjectForKey(view, kInputHelperTapGusture, kInputHelperTapGusture);
for (NSNumber *key in sortedOriginYArray){
UIView *inputField = [getAssociatedObjectForKey(view, kInputHelperRootViewAllInputFieldOriginYDictionary) objectForKey:key];
[getAssociatedObjectForKey(view, kInputHelperRootViewSortedInputFieldArray) addObject:inputField];
if ([inputField isKindOfClass:[UITextField class]]) {
((UITextField *)inputField).inputAccessoryView = inputAccessoryV
} else if([inputField isKindOfClass:[UITextView class]]){
((UITextView *)inputField).inputAccessoryView = inputAccessoryV
} else if([inputField isKindOfClass:[UISearchBar class]]){
((UISearchBar *)inputField).inputAccessoryView = inputAccessoryV
- (void)setupInputHelperForView:(UIView *)view withDismissType:(InputHelperDismissType)dismissType{
[self setupInputHelperForView:view withDismissType:dismissType doneBlock:nil];
- (void)dismissInputHelper{
[self didClickButtonDone];
- (void)setupValidationType:(ValidationType)type forInputField:(UIView *)inputField {
setAssociatedObjectForKey(inputField, kInputHelperValidationType, @(type));
switch (type) {
case ValidationTypeNumberInt:
[self setKeyBoardType:UIKeyboardTypeNumberPad forInputField:inputField];
case ValidationTypePhone:
[self limitTextLength:11 forInputField:inputField];
[self setKeyBoardType:UIKeyboardTypePhonePad forInputField:inputField];
[self setKeyBoardType:UIKeyboardTypeDefault forInputField:inputField];
- (void)limitTextLength:(NSInteger)length forInputField:(UIView *)inputField{
setAssociatedObjectForKey(inputField, kInputHelperTextLengthLimit, @(length));
#pragma mark -
- (void)updateFirstResponder:(NSNotification *)aNotification {
[self updateButtonEnabledStateForInputField:[self getFirstResponder]];
- (void)checkInputFieldInView:(UIView *)view
withViewOriginY:(CGFloat)y
for (UIView *subView in view.subviews){
if (subView.hidden == YES) {
if ([subView isKindOfClass:[UITextField class]] ||
[subView isKindOfClass:[UITextView class]] ||
[subView isKindOfClass:[UISearchBar class]]) {
NSNumber *key = [NSNumber numberWithFloat: y + subView.frame.origin.y];
NSMutableDictionary *dic = getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewAllInputFieldOriginYDictionary);
[dic setObject:subView forKey:key];
[self checkInputFieldInView:subView
withViewOriginY:y + subView.frame.origin.y];
- (UIView *)getFirstResponder
for (UIView *tf in getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewSortedInputFieldArray)) {
if ([tf isFirstResponder]) {
- (void)didClickButtonPrevious
UIView *firstResponder = [self getFirstResponder];
UIView *previousInputField = firstR
NSArray *sortedInputFields = getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewSortedInputFieldArray);
if (![firstResponder isEqual:[sortedInputFields firstObject]]) {
previousInputField = [sortedInputFields objectAtIndex:[sortedInputFields indexOfObject:firstResponder] - 1];
[previousInputField becomeFirstResponder];
[self updateButtonEnabledStateForInputField:previousInputField];
- (void)didClickButtonNext
UIView *firstResponder = [self getFirstResponder];
UIView *nextInputField = firstR
NSArray *sortedInputFields = getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewSortedInputFieldArray);
if (![firstResponder isEqual:[sortedInputFields lastObject]]) {
nextInputField = [sortedInputFields objectAtIndex:[sortedInputFields indexOfObject:firstResponder] + 1];
[nextInputField becomeFirstResponder];
[self updateButtonEnabledStateForInputField:nextInputField];
- (void)didClickButtonDone
[[self getFirstResponder] resignFirstResponder];
CGRect frame = _currentRootView.
frame.origin.y = [getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewOriginalOriginY) floatValue];
[UIView animateWithDuration:0.3f animations:^{
_currentRootView.frame =
InputHelperDoneBlock doneBlock = getAssociatedObjectForKey(self.currentRootView, kInputHelperDoneBlock);
if (doneBlock) {
//callback what??
doneBlock(nil);
- (void)updateButtonEnabledStateForInputField:(UIView *)inputField
if (inputField) {
NSInteger dismissType = [getAssociatedObjectForKey(_currentRootView, kInputHelperDismissType) integerValue];
UIToolbar *toolBar = dismissType == InputHelperDismissTypeCleanMaskView ? _toolBarForCleanMaskView : _toolB
UIBarButtonItem *previousBarItem = (UIBarButtonItem *)[[toolBar items] objectAtIndex:0];
UIBarButtonItem *nextBarItem = (UIBarButtonItem *)[[toolBar items] objectAtIndex:1];
NSArray *sortedInputFields = getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewSortedInputFieldArray);
[previousBarItem setEnabled:[inputField isEqual:[sortedInputFields firstObject]] ? NO : YES];
[nextBarItem setEnabled:[inputField isEqual:[sortedInputFields lastObject]] ? NO : YES];
[self animatedMoveRootViewForInputField:inputField];
- (void)animatedMoveRootViewForInputField:(UIView *)inputField
CGPoint windowPoint = [inputField.superview convertPoint:inputField.frame.origin toView:[[UIApplication sharedApplication]keyWindow]];
CGFloat topY = 74.0f;
CGFloat buttomY = [[UIScreen mainScreen]applicationFrame].size.height - _keyboardSize.height - 80;
CGRect frame = _currentRootView.
if (windowPoint.y & topY ) {
frame.origin.y +=
(1 + (int)((topY - windowPoint.y) / _perMoveDistanceForInputField)) * _perMoveDistanceForInputF
if (frame.origin.y & 0) {
frame.origin.y = 0;
} else if (windowPoint.y & buttomY) {
frame.origin.y -= ((1 + (int)((windowPoint.y - buttomY) / _perMoveDistanceForInputField)) * _perMoveDistanceForInputField);
[UIView animateWithDuration:0.3f animations:^{
_currentRootView.frame =
#pragma mark - Notification methods
- (void) keyboardWillShow:(NSNotification *) notif
if (getAssociatedObjectForKey(_currentRootView, kInputHelperRootViewOriginalOriginY) == nil) {
setAssociatedObjectForKey(_currentRootView, kInputHelperRootViewOriginalOriginY, @(_currentRootView.frame.origin.y));
NSString *str = getAssociatedObjectForKey(_currentRootView, kInputHelperTapGusture);
BOOL hasAddGusture = NO;
for(id gusture in _currentRootView.gestureRecognizers){
if ([gusture isKindOfClass:[InputHelperTapGusture class]] && ((InputHelperTapGusture *)gusture).tag == tapTag) {
hasAddGusture = YES;
if ([str isEqualToString:kInputHelperTapGusture] && !hasAddGusture) {
InputHelperTapGusture *tap = [[InputHelperTapGusture alloc]initWithTarget:self action:@selector(didClickButtonDone)];
tap.tag = tapT
[_currentRootView addGestureRecognizer:tap];
[self updateButtonEnabledStateForInputField:[self getFirstResponder]];
- (void) keyboardWillHide:(NSNotification *) notif
NSString *str = getAssociatedObjectForKey(_currentRootView, kInputHelperTapGusture);
if ([str isEqualToString:kInputHelperTapGusture]) {
for(id gusture in _currentRootView.gestureRecognizers){
if ([gusture isKindOfClass:[InputHelperTapGusture class]] && ((InputHelperTapGusture *)gusture).tag == tapTag) {
[_currentRootView removeGestureRecognizer:gusture];
- (void)updateInputFieldText:(NSNotification *)notif{
[self checkInputField:notif.object];
#pragma mark - Validation
- (void)setKeyBoardType:(UIKeyboardType) keyboardType forInputField:(UIView *)inputField{
if ([inputField isKindOfClass:[UITextField class]]) {
((UITextField *)inputField).keyboardType = keyboardT
} else if([inputField isKindOfClass:[UITextView class]]){
((UITextView *)inputField).keyboardType = keyboardT
} else if([inputField isKindOfClass:[UISearchBar class]]){
((UISearchBar *)inputField).keyboardType = keyboardT
- (NSString *)getTextForInputField:(UIView *)inputField{
if ([inputField isKindOfClass:[UITextField class]]) {
return ((UITextField *)inputField).
} else if([inputField isKindOfClass:[UITextView class]]){
return ((UITextView *)inputField).
} else if([inputField isKindOfClass:[UISearchBar class]]){
return ((UISearchBar *)inputField).
- (void)setText:(NSString *)text forInputField:(UIView *)inputField{
if ([inputField isKindOfClass:[UITextField class]]) {
((UITextField *)inputField).text =
} else if([inputField isKindOfClass:[UITextView class]]){
((UITextView *)inputField).text =
} else if([inputField isKindOfClass:[UISearchBar class]]){
((UISearchBar *)inputField).text =
- (void)checkText:(NSString *)text forInputField:(UIView *)inputField validation:(NSString *)validation{
NSInteger preLength = [getAssociatedObjectForKey(inputField, kInputHelperInputFiedlTextLength) integerValue];
NSLog(@current text %@ len %d,prelen %d,text,[text length],preLength);
if (![self isTextAvailable:text forValidation:validation]) {
[self setText:[text substringToIndex:MAX(MAX(preLength - 1, 0), text.length -1)] forInputField:inputField];
setAssociatedObjectForKey(inputField, kInputHelperInputFiedlTextLength, @(preLength));
setAssociatedObjectForKey(inputField, kInputHelperInputFiedlTextLength, @(text.length));
- (void)checkInputField:(UIView *)inputField{
NSInteger type = [getAssociatedObjectForKey(inputField, kInputHelperValidationType) integerValue];
//length limit
NSInteger limitLength = [getAssociatedObjectForKey(inputField, kInputHelperTextLengthLimit) integerValue];
if (limitLength) {
NSString *text = [self getTextForInputField:inputField];
if (text.length && text.length & limitLength) {
[self setText:[text substringToIndex:limitLength]forInputField:inputField];
NSString *text = [self getTextForInputField:inputField];
if (text.length) {
switch (type) {
case ValidationTypeNone:
//do nothing
case ValidationTypeNoWhiteSpace:
[self setText:[text trimmedString] forInputField:inputField];
case ValidationTypeNumberInt:
[self checkText:text forInputField:inputField validation:INT_NUMBER_SET];
case ValidationTypeAlphabetAndNumber:
[self checkText:text forInputField:inputField validation:ALPHABET_NUMBER_SET];
case ValidationTypePhone:
[self checkText:text forInputField:inputField validation:PHONE_SET];
- (BOOL)isTextAvailable:(NSString *)text
forValidation:(NSString *)validation {
NSPredicate *regexPredicate = [NSPredicate predicateWithFormat:@SELF MATCHES %@,validation];
return [regexPredicate evaluateWithObject:text];
@implementation NSString (InputHelper)
- (NSString *)trimmedString {
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'ios 如何实现在一个输入框里相同的字母不能超过三次??_百度知道
ios 如何实现在一个输入框里相同的字母不能超过三次??
提问者采纳
for (int i = 0:i];=0x4E00 && c &
unichar c = [string characterAtI汉字
return NO; i&/计算汉字的个数- (NSInteger)chineseCountOfS=0x9FA5)
characterCount++;}&#47.// i&=0x4E00 && c &
if (string:(NSString *)string{
int characterCount = 0;计算字母的个数- (NSInteger)characterCountOfS/英文
return characterC
if (string./
if (c &=0x9FA5)
ChineseCount++ ;=0x4E00 && c &=0x9FA5)
return YES;
if (c & i++) {
unichar c = [string characterAtIndex:0];&#47.length == 0) {
return 0:(NSString *)string{
int ChineseCount = 0,调用即可)//汉字
return ChineseC步骤创建一个NSString的类别;/&#47:i].length == 0) {
return NO; i++) {
unichar c = [string characterAtI判断是否为汉字- (BOOL)isChinesecharacter.m文件(或者在你想用的文件里直接粘贴。将一下代码复制到NSString 的类别的方法&#47.length == 0) {
for (int i = 0;/英文
}}/&#47:(NSString *)string{
if (string
不太明白这个方法,能解释一下吗
提问者评价
太给力了,你的回答完美地解决了我的问题,非常感谢!
来自团队:
其他类似问题
为您推荐:
ios的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁4207人阅读
iOS(275)
有一个输入框,输入框内输入文字,文字字数限制在20字。我采用了UITextField作为我的输入框控件,并且在委托方法:
#define kMaxLength 20
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (toBeString.length & kMaxLength && range.length!=1){
textField.text = [toBeString substringToIndex:kMaxLength];
return NO;
return YES;
这样实现的结果是:对于纯字符的统计没有什么问题,但当使用拼音输入法时,该委托方法中的最后一个参数string接受的是输入的字母,而不是选择的汉字,造成的结果是,当想输入文字“我在编程”,输入拼音“wozaibiancheng”,每输入一个字母便会进入委托方法,统计的字符长度是字母的长度,实际上汉字还未超过限制长度,但是字母的长度超过了导致无法继续输入。
所以实现的代码如下。
&1&在init时候注册notification:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFiledEditChanged:)
name:@&UITextFieldTextDidChangeNotification&
object:myTextField];&2&实现监听方法:
-(void)textFiledEditChanged:(NSNotification *)obj{
UITextField *textField = (UITextField *)obj.
NSString *toBeString = textField.
NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式
if ([lang isEqualToString:@&zh-Hans&]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写
UITextRange *selectedRange = [textField markedTextRange];
//获取高亮部分
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
// 没有高亮选择的字,则对已输入的文字进行字数统计和限制
if (!position) {
if (toBeString.length & kMaxLength) {
textField.text = [toBeString substringToIndex:kMaxLength];
// 有高亮选择的字符串,则暂不对文字进行统计和限制
// 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况
if (toBeString.length & kMaxLength) {
textField.text = [toBeString substringToIndex:kMaxLength];
&3&在dealloc中-(void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self
name:@&UITextFieldTextDidChangeNotification&
object:_albumNameTextField];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1009522次
积分:11534
积分:11534
排名:第1476名
原创:201篇
转载:339篇
评论:170条
(4)(13)(20)(13)(13)(13)(13)(12)(18)(31)(11)(14)(24)(13)(4)(19)(13)(12)(7)(10)(3)(6)(17)(23)(33)(18)(17)(29)(18)(1)(8)(2)(4)(8)(6)(12)(4)(10)(5)(3)(2)(1)(2)(3)(5)(5)(1)(1)(2)(1)(2)}

我要回帖

更多关于 html实现输入框 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信