//
// UITagTextField.h
//
// Created by Peace on 6/10/15.
//
#import <UIKit/UIKit.h>
@protocol UITagTextFieldDelegate;
@interface UITagTextField : UITextField <UIKeyInput>
@property (nonatomic, assign) id<UITagTextFieldDelegate> tagDelegate;
@property (nonatomic, assign) BOOL isWillDelete;
@end
@protocol UITagTextFieldDelegate <NSObject>
@optional
- (void)textFieldDidDelete:(UITagTextField *)textField;
@end
//
// UITagTextField.m
//
// Created by Peace on 6/10/15.
//
#import "UITagTextField.h"
@implementation UITagTextField
- (void)deleteBackward
{
[super deleteBackward];
if (!self.isWillDelete) {
if ([_tagDelegate respondsToSelector:@selector(textFieldDidDelete:)]){
[_tagDelegate textFieldDidDelete:self];
}
}
}
- (BOOL)keyboardInputShouldDelete:(UITextField *)textField
{
BOOL shouldDelete = YES;
self.isWillDelete = YES;
if ([UITextField instancesRespondToSelector:_cmd]) {
BOOL (*keyboardInputShouldDelete)(id, SEL, UITextField *) = (BOOL (*)(id, SEL, UITextField *))[UITextField instanceMethodForSelector:_cmd];
if (keyboardInputShouldDelete) {
shouldDelete = keyboardInputShouldDelete(self, _cmd, textField);
}
}
if (![textField.text length] && [[[UIDevice currentDevice] systemVersion] intValue] >= 8) {
//[self deleteBackward];
if ([_tagDelegate respondsToSelector:@selector(textFieldDidDelete:)]){
[_tagDelegate textFieldDidDelete:self];
}
}
return shouldDelete;
}
@end