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
//
//  PBMultiSelectPersonCell.m
//  IphoneBIMe
//
//  Created by zjf on 2021/1/7.
//  Copyright © 2021 ProBIM. All rights reserved.
//
 
#import "PBMultiSelectPersonCell.h"
#import "PBUserModel.h"
@interface PBMultiSelectPersonCell()
@property (nonatomic, weak) UILabel *nameShorthandL;
@property (nonatomic, weak) UILabel *nameL;
@property (nonatomic, weak) UILabel *typeL;
@property (nonatomic, weak) UIImageView *chooseV;
@end
@implementation PBMultiSelectPersonCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UIImageView *chooseV = [[UIImageView alloc] init];
    [self.contentView addSubview:chooseV];
    [chooseV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.left.equalTo(self.contentView).offset(12);
        make.centerY.equalTo(self.contentView);
    }];
    UIView *nameBgV = [[UIView alloc] init];
    nameBgV.backgroundColor = PBColor(40, 58, 79);
    [self.contentView addSubview:nameBgV];
    [nameBgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.left.equalTo(chooseV.mas_right).offset(10);
        make.centerY.equalTo(self.contentView);
    }];
    [nameBgV circleViewWithRadius:6];
    UILabel *nameShorthandL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:YES Font:14];
    nameShorthandL.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:nameShorthandL];
    [nameShorthandL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(nameBgV);
    }];
    UILabel *nameL = [UILabel z_labelWithText:@"" Color:PBColor(40, 58, 79) isBold:YES Font:14];
    [self.contentView addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@20);
        make.left.equalTo(nameBgV.mas_right).offset(10);
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-160);
    }];
    UILabel *typeL = [UILabel z_labelWithText:@"" Color:PBColor(97, 111, 125) isBold:NO Font:13];
    typeL.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:typeL];
    [typeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@16);
        make.left.equalTo(nameL.mas_right).offset(30);
        make.right.equalTo(self.contentView).offset(-35);
        make.centerY.equalTo(self.contentView);
    }];
    self.nameShorthandL = nameShorthandL;
    self.nameL = nameL;
    self.typeL = typeL;
    self.chooseV = chooseV;
}
- (void)setUserModel:(PBUserModel *)userModel {
    _userModel = userModel;
    if (userModel.isSelect) {
        self.chooseV.image = [UIImage imageNamed:@"select_circle_select"];
    }else {
        self.chooseV.image = [UIImage imageNamed:@"select_circle"];
    }
    BOOL isChiness = [self IsChinese:userModel.RealName];
    if (isChiness) {
        self.nameShorthandL.text = [userModel.RealName substringFromIndex:userModel.RealName.length - 1];
    }else {
        self.nameShorthandL.text = [userModel.RealName substringToIndex:1];
    }
    self.nameL.text = userModel.RealName;
    NSArray *role = userModel.RoleNames;
    if (role.count > 0) {
        self.typeL.text = role[0];
    }
}
 
- (BOOL)IsChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff){
            return YES;
        }
      }
    return NO;
}
- (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