iOS开发-UITextView

iOS TextField 监听实时输入 避免删除键失灵 监

2017-04-26  本文已影响0人  WS_0909

如果有帮助到你就给个赞吧 谢谢咯...

// 添加监听方法

[_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

// MARK:  =========  textfield 监听实现  =========

-(void)textFieldDidChange :(UITextField *)theTextField{

if (theTextField.text.length != 11) {  //  11位数字

_loginButton.userInteractionEnabled = NO;

[_loginButton setBackgroundColor:kRGBColor(209, 209, 209, 1)];

} else {

_loginButton.userInteractionEnabled = YES;

[_loginButton setBackgroundColor:kBackgroundColor];

}

}```

   UITextFieldDelegate  代理方法  避免删除键失灵

if (range.length == 1 && string.length == 0) {

return YES;

} else if ([textField isEqual:self.accountTF]) {

return textField.text.length < 11;

}

return YES;

}


监听删除键的点击要添加textField分类

.h


//// Created by SDL on 6/20/16.// Copyright © 2016 SDL. All rights reserved.

import "UITextField+Monitor_TextField.h"

@protocol WsTextFieldDelegate
@optional

@end

/**

*/

extern NSString * const WsTextFieldDidDeleteBackwardNotification;


.m

//
// Created by SDL on 6/20/16.
// Copyright © 2016 SDL. All rights reserved.
//

import "UITextField+Monitor_TextField.h"

import <objc/objc-runtime.h>

NSString * const WsTextFieldDidDeleteBackwardNotification = @"com.whojun.textfield.did.notification";

@implementation UITextField (Monitor_TextField)

@end

上一篇下一篇

猜你喜欢

热点阅读