JLChen
2021-11-04 1443556e9ccb1a19ed8e6710c16c8adc4d4f4fb3
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
//  Copyright © 2019 dahua. All rights reserved.
//
 
#import "LCInputTextField.h"
 
typedef void(^ActionBlock)(void);
 
@interface LCInputTextField ()
 
/// icon
@property (strong, nonatomic) UIImageView *iconView;
 
/// 动作暂存
@property (copy, nonatomic) ActionBlock layoutBlock;
 
@end
 
@implementation LCInputTextField
 
+ (instancetype)creatTextFieldWithResult:(void (^)(NSString *result))result {
    LCInputTextField *textField = [LCInputTextField new];
    [textField setupViewWith:result];
    return textField;
}
 
- (void)setupViewWith:(void (^)(NSString *result))result {
    
    self.titleLable = [[UILabel alloc] init];
    self.titleLable.font = [UIFont lcFont_t4];
    [self addSubview:self.titleLable];
    
    self.iconView = [UIImageView new];
    [self addSubview:self.iconView];
 
    self.textField = [DHTextField lcTextFieldWithResult:result];
    [self addSubview:self.textField];
    
    self.textField.layer.cornerRadius = 2;
    
    self.sendCodeBtn = [LCButton lcButtonWithType:LCButtonTypeCode];
    [self addSubview:self.sendCodeBtn];
    [self layoutIfNeeded];
    
}
 
- (void)updateConstraints {
    [super updateConstraints];
    weakSelf(self);
    switch (self.style) {
        case LCTEXTFIELD_STYLE_TITLE: {
            [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self);
                make.top.mas_equalTo(self.mas_top);
            }];
            [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.titleLable.mas_bottom).offset(10);
                make.left.mas_equalTo(self.mas_left);
                make.right.mas_equalTo(self);
                make.height.mas_equalTo(46);
                make.bottom.mas_equalTo(self.mas_bottom);
            }];
            self.textField.layer.borderWidth = 1.0f;
            self.textField.layer.borderColor = [UIColor dhcolor_c52].CGColor;
        }
        break;
 
        case LCTEXTFIELD_STYLE_PHONE: {
            self.iconView.image =LC_IMAGENAMED(@"login_icon_user");
            [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.mas_left);
                make.centerY.mas_equalTo(self.mas_centerY);
                make.bottom.mas_equalTo(self.mas_bottom).offset(-11);
                make.width.mas_equalTo(self.iconView.mas_height).multipliedBy(1.0);
            }];
            
            [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.iconView.mas_right).offset(10);
                make.right.mas_equalTo(self.mas_right);
                make.height.mas_equalTo(46);
                make.centerY.mas_equalTo(self.mas_centerY);
                make.bottom.mas_equalTo(self.mas_bottom).offset(-11);
            }];
            self.layoutBlock = ^{
                [weakself setBorderWithView:weakself Style:LC_BORDER_DRAW_BOTTOM borderColor:[UIColor dhcolor_c59] borderWidth:1.0];
            };
          
        }
        break;
        case LCTEXTFIELD_STYLE_CODE: {
            
            [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self).offset(10);
                make.height.mas_equalTo(46);
                make.width.mas_equalTo(self).multipliedBy(0.6);
                make.centerY.mas_equalTo(self.mas_centerY);
                make.bottom.mas_equalTo(self.mas_bottom).offset(-11);
            }];
            [self.sendCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.textField.mas_right);
                make.top.mas_equalTo(self.mas_top);
                make.right.mas_equalTo(self.mas_right).offset(-10);
                make.centerY.mas_equalTo(self.mas_centerY);
                make.bottom.mas_equalTo(self.mas_bottom).offset(-11);
            }];
            self.layoutBlock = ^{
                [weakself setBorderWithView:weakself Style:LC_BORDER_DRAW_BOTTOM borderColor:[UIColor dhcolor_c59] borderWidth:1.0];
            };
        }
            break;
        case LCTEXTFIELD_STYLE_WIFI: {
            [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self);
                make.top.mas_equalTo(self.mas_top);
            }];
        }
        break;
        case LCTEXTFIELD_STYLE_PASSWORD: {
            [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self);
                make.top.mas_equalTo(self.mas_top);
            }];
        }
        break;
 
        default:
            break;
    }
 
}
 
-(void)layoutSubviews{
    [super layoutSubviews];
    if (self.layoutBlock) {
        self.layoutBlock();
    }
}
 
 
 
@end