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
//
//  PBUserCollectionViewCell.m
//  IphoneBIMe
//
//  Created by zjf on 2021/1/8.
//  Copyright © 2021 ProBIM. All rights reserved.
//
 
#import "PBUserCollectionViewCell.h"
#import "PBUserModel.h"
@interface PBUserCollectionViewCell()
@property (nonatomic, weak) UILabel *nameL;
@end
@implementation PBUserCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UIView *bgV = [[UIView alloc] init];
    bgV.backgroundColor = PBColor(40, 58, 79);
    [self.contentView addSubview:bgV];
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.contentView);
    }];
    [bgV circleViewWithRadius:6];
    UILabel *nameL = [UILabel z_labelWithText:@"" Color:[UIColor whiteColor] isBold:YES Font:14];
    nameL.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(bgV);
    }];
    self.nameL = nameL;
}
- (void)setUserModel:(PBUserModel *)userModel {
    _userModel = userModel;
    BOOL isChiness = [self IsChinese:userModel.RealName];
    if (isChiness) {
        self.nameL.text = [userModel.RealName substringFromIndex:userModel.RealName.length - 1];
    }else {
        self.nameL.text = [userModel.RealName substringToIndex:1];
    }
}
- (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;
}
 
@end