配合ReactiveObjC框架中提供的rac_textSignal的API就可以全面的监听按钮输入
[_searchTF.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
}];
注意
通过UITextFieldDelegate方法- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 来监听输入时会不准确, 此方法监听到的text会少最后一个输入的字符或文字, 一般此方法用来做控制字数限制的操作
设置leftView的大小
生成一个继承UITextField的子类, 重写leftViewRectForBounds方法
@interface CRLTextField : UITextField
@end
@implementation CRLTextField
- (CGRect)leftViewRectForBounds:(CGRect)bounds {
return CGRectMake(0, 0, 32, 32);
}
- (CGRect)rightViewRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.size.width-32, 0, 32, 32);
}
@end










网友评论