zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  PBInputCodeTableViewCell.m
//  IphoneBIMe
//
//  Created by zjf on 2020/7/16.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBInputCodeTableViewCell.h"
@interface PBInputCodeTableViewCell()<UITextFieldDelegate>
@property (nonatomic, weak) UIView *codeBgV;
@property (nonatomic, weak) UIImageView *logoImageV;
@property (nonatomic, weak) UITextField *codeTF;
@property (nonatomic, weak) UIView *linV;
@end
 
@implementation PBInputCodeTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    self.contentView.backgroundColor = PromptColor;
    UIView *codeBgV = [[UIView alloc] init];
    codeBgV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:codeBgV];
    [codeBgV mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(self.contentView);
         make.left.equalTo(self.contentView);
         make.right.equalTo(self.contentView);
         make.bottom.equalTo(self.contentView).offset(-20);
    }];
    [codeBgV circleViewWithRadius:6];
    UIImageView *logoImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_unknown"]];
    [self.contentView addSubview:logoImageV];
    [logoImageV mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.equalTo(codeBgV).offset(26);
         make.centerX.equalTo(codeBgV);
         make.size.mas_equalTo(CGSizeMake(36, 36));
    }];
    UIView *linV = [[UIView alloc] init];
    linV.backgroundColor = PBColor(233, 235, 237);
    [self.contentView addSubview:linV];
    [linV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(codeBgV).offset(-31);
        make.left.equalTo(codeBgV).offset(67);
        make.right.equalTo(codeBgV).offset(-67);
        make.height.equalTo(@1);
    }];
    UITextField *codeTF = [[UITextField alloc] init];
    codeTF.placeholder = @"输入自有企业服务编码";
    codeTF.textAlignment= NSTextAlignmentCenter;
    codeTF.textColor = PBColor(40, 58, 79);
    codeTF.font = [UIFont fontWithName:Coarse size:16.0];
    codeTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    codeTF.clearButtonMode = UITextFieldViewModeAlways;
    codeTF.delegate = self;
    codeTF.returnKeyType = UIReturnKeyDone;
    [self.contentView addSubview:codeTF];
    [codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(linV).offset(-1);
        make.left.right.equalTo(linV);
        make.height.equalTo(@34);
    }];
    self.codeBgV = codeBgV;
    self.logoImageV = logoImageV;
    self.codeTF = codeTF;
    self.linV = linV;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    self.logoImageV.image = [UIImage imageNamed:@"logo_unknown_nor"];
    if ([[_dict valueForKey:@"err"] isEqualToString:@"err"]) {
        [_dict setValue:@"" forKey:@"err"];
        self.codeBgV.backgroundColor = [UIColor whiteColor];
        self.codeTF.textColor = PBColor(40, 58, 79);
        if (self.SolveErr) {
            self.SolveErr();
        }
    }
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    self.logoImageV.image = [UIImage imageNamed:@"logo_unknown"];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.codeTF resignFirstResponder];
    if (self.GetEnterpriseBlock) {
        self.GetEnterpriseBlock(textField.text);
    }
    return YES;
}
- (void)setDict:(NSMutableDictionary *)dict {
    _dict = dict;
    if ([[dict valueForKey:@"err"] isEqualToString:@"err"]) {
        self.codeBgV.backgroundColor = PBColor(244, 21, 21);
        self.logoImageV.image = [UIImage imageNamed:@"logo_unknown_erro"];
        self.codeTF.textColor = [UIColor whiteColor];
        self.codeTF.text = [dict valueForKey:@"code"];
    }else {
        self.codeBgV.backgroundColor = [UIColor whiteColor];
        self.logoImageV.image = [UIImage imageNamed:@"logo_unknown"];
        self.codeTF.text = [dict valueForKey:@"code"];;
        self.codeTF.textColor = PBColor(40, 58, 79);
    }
}
 
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
@end