-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathFileChangesIntroduceCell.m
60 lines (53 loc) · 2.88 KB
/
FileChangesIntroduceCell.m
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
//
// FileChangesIntroduceCell.m
// Coding_iOS
//
// Created by Ease on 15/6/1.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "FileChangesIntroduceCell.h"
@interface FileChangesIntroduceCell ()
@property (strong, nonatomic) UILabel *contentL;
@end
@implementation FileChangesIntroduceCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = kColorTableBG;
if (!_contentL) {
_contentL = [UILabel new];
[self.contentView addSubview:_contentL];
[_contentL mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, kPaddingLeftWidth, 10, kPaddingLeftWidth));
}];
}
}
return self;
}
- (void)setFilesCount:(NSInteger)filesCount insertions:(NSInteger)insertions deletions:(NSInteger)deletions{
_contentL.attributedText = [self p_styleStrFromFilesCount:filesCount insertions:insertions deletions:deletions];
}
- (NSAttributedString *)p_styleStrFromFilesCount:(NSInteger)filesCount insertions:(NSInteger)insertions deletions:(NSInteger)deletions{
NSString *filesCountStr = [NSString stringWithFormat:@"%ld个文件", (long)filesCount];
NSString *insertionsStr = [NSString stringWithFormat:@"%ld个新增", (long)insertions];
NSString *deletionsStr = [NSString stringWithFormat:@"%ld个删除", (long)deletions];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ 共%@和%@", filesCountStr, insertionsStr, deletionsStr]];
NSDictionary *attrLeft = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:15],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x4E90BF"]};
NSDictionary *attrRight = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:15],
NSForegroundColorAttributeName : kColor222};
NSDictionary *attrCommon = @{NSFontAttributeName : [UIFont systemFontOfSize:15],
NSForegroundColorAttributeName : kColor222};
[attrString addAttributes:attrLeft range:NSMakeRange(0, filesCountStr.length)];
[attrString addAttributes:attrRight range:NSMakeRange(filesCountStr.length + 2, insertionsStr.length)];
[attrString addAttributes:attrRight range:NSMakeRange(filesCountStr.length + insertionsStr.length + 3, deletionsStr.length)];
[attrString addAttributes:attrCommon range:NSMakeRange(filesCountStr.length, 2)];
[attrString addAttributes:attrCommon range:NSMakeRange(filesCountStr.length + insertionsStr.length + 2, 1)];
return attrString;
}
+ (CGFloat)cellHeight{
return 44.0;
}
@end