-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITextValidator.m
98 lines (77 loc) · 1.71 KB
/
UITextValidator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// UITextValidator.m
// SnapBi
//
// Created by Austin Amoruso on 3/27/14.
// Copyright (c) 2014 SnapBi. All rights reserved.
//
#import "UITextValidator.h"
#import "UIHelper.h"
@interface UITextValidator()
@property (strong,atomic) UIView * pText;
@property (strong,atomic) UITableViewCell * pCell;
@property (atomic) bool pEnabled;
@property (atomic) bool pFlashing;
@property (atomic) bool pValid;
@property (atomic,strong) bool (^pBlock) (void);
@property (atomic,strong) id me;
@end
@implementation UITextValidator
-(void)setTextView:(UIView *)view
{
self.pText = view;
self.me = self;
if([self.pText isKindOfClass:[UITextField class]])
{
UITextField * utf = (UITextField *)self.pText;
[utf addTarget:self.me action:@selector(check) forControlEvents:UIControlEventEditingChanged];
}
else if([view isKindOfClass:[UITextView class]])
{
UITextView * utv = (UITextView *)self.pText;
[utv setDelegate:self];
}
}
-(void)setRule:(bool (^)(void))block
{
self.pBlock = block;
}
-(void)setFlashView:(UITableViewCell *)view
{
self.pCell = view;
}
-(void)setEnabled:(bool)on
{
self.pEnabled = on;
[self check];
}
- (void)textViewDidChange:(UITextView *)textView
{
[self check];
}
-(BOOL)check
{
if(self.pEnabled)
{
self.pValid = false;
if(self.pBlock())
{
self.pValid = true;
[UIHelper stopFlashCell:self.pCell];
}
else if(!self.pFlashing)
{
[UIHelper flashCell:self.pCell];
}
}
else if(self.pFlashing)
{
[UIHelper stopFlashCell:self.pCell];
self.pFlashing = false;
}
}
-(bool)isValid
{
return self.pValid;
}
@end