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
//
//  PBDocListTableViewCell.m
//  IphoneBIMe
//
//  Created by zjf on 2018/7/31.
//  Copyright © 2018年 ProBIM. All rights reserved.
//
 
#import "PBDocListTableViewCell.h"
#import "PBDocModel.h"
 
@interface PBDocListTableViewCell()
@property (nonatomic, weak) UIImageView *docTypeImageV;
@property (nonatomic, weak) UILabel *docNameL;
@property (nonatomic, weak) UILabel *creatTimeL;
@property (nonatomic, weak) UILabel *docSizeL;
@end
 
@implementation PBDocListTableViewCell
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return  self;
}
 
- (void)setupUI {
    UIImageView *docTypeImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:docTypeImageV];
    [docTypeImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(25);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    
    UILabel *docNameL = [UILabel z_labelWithText:@"" Color:PBColor(40, 58, 79) isBold:YES Font:16];
    docNameL.numberOfLines = 0;
    [self.contentView addSubview:docNameL];
    [docNameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(9);
        make.left.equalTo(docTypeImageV.mas_right).offset(15);
        make.right.equalTo(self.contentView).offset(-25);
    }];
    
    UILabel *creatTimeL = [UILabel z_labelWithText:@"" Color:PBColor(166, 174, 182) isBold:YES Font:12];
    [self.contentView addSubview:creatTimeL];
    [creatTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(docNameL.mas_bottom).offset(8);
        make.left.equalTo(docNameL);
        make.right.equalTo(docNameL).offset(-80);
        make.height.equalTo(@16);
    }];
    
    UILabel *docSizeL = [UILabel z_labelWithText:@"" Color:PBColor(97, 111, 125) isBold:YES Font:12];
    docSizeL.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:docSizeL];
    [docSizeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(creatTimeL);
        make.right.equalTo(self.contentView).offset(-20);
        make.size.mas_equalTo(CGSizeMake(100, 20));
        make.bottom.equalTo(self.contentView).offset(-12);
    }];
    
    self.docTypeImageV = docTypeImageV;
    self.docNameL = docNameL;
    self.creatTimeL = creatTimeL;
    self.docSizeL = docSizeL;
}
 
- (void)setDocModel:(PBDocModel *)docModel {
    _docModel = docModel;
    UIImage *image;
    NSString *fileSize;
    if ([docModel.FileSize isEqualToString:@"0"]) {
        image = [UIImage imageNamed:@"Doc_type_folder"];
        fileSize = nil;
    }else {
        NSString *type = [docModel.FileExtensions stringByReplacingOccurrencesOfString:@"." withString:@""];
        NSString *imageName = [NSString stringWithFormat:@"Doc_type_%@",[type lowercaseString]];
        image = [UIImage imageNamed:imageName];
        if (image == nil) {
            image = [UIImage imageNamed:@"Doc_type_ unknown"];
        }
        
        fileSize = [NSByteCountFormatter stringFromByteCount:[docModel.FileSize doubleValue] countStyle:NSByteCountFormatterCountStyleBinary];
    }
    _docTypeImageV.image = image;
    _docSizeL.text = fileSize;
    _docNameL.text = docModel.FileName;
    NSRange range = [docModel.CreateDate rangeOfString:@":"];
    NSString *date = [docModel.CreateDate substringToIndex:range.location + 3];
    _creatTimeL.text = date;
    
}
 
- (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