forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCodeListCell.m
More file actions
executable file
·84 lines (71 loc) · 3.31 KB
/
ProjectCodeListCell.m
File metadata and controls
executable file
·84 lines (71 loc) · 3.31 KB
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
//
// ProjectCodeListCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14/10/29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#define kCode_IconViewWidth 25.0
#define kCode_ContentLeftPading (kPaddingLeftWidth+kCode_IconViewWidth+10)
#import "ProjectCodeListCell.h"
@interface ProjectCodeListCell ()
@property (strong, nonatomic) UIImageView *leftIconView;
@property (strong, nonatomic) UILabel *fileName, *commitTime, *commitInfo, *commitorName;
@end
@implementation ProjectCodeListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.backgroundColor = [UIColor clearColor];
// Initialization code
if (!_leftIconView) {
_leftIconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([self.class cellHeight] - kCode_IconViewWidth)/2, kCode_IconViewWidth, kCode_IconViewWidth)];
[self.contentView addSubview:_leftIconView];
}
if (!_fileName) {
_fileName = [[UILabel alloc] initWithFrame:CGRectMake(kCode_ContentLeftPading, 10, kScreen_Width-kCode_ContentLeftPading-30, 20)];
_fileName.font = [UIFont systemFontOfSize:15];
_fileName.textColor = [UIColor colorWithHexString:@"0x222222"];
[self.contentView addSubview:_fileName];
}
if (!_commitTime) {
_commitTime = [[UILabel alloc] initWithFrame:CGRectMake(kCode_ContentLeftPading, [self.class cellHeight]-25, kScreen_Width-kCode_ContentLeftPading-30, 20)];
_commitTime.font = [UIFont systemFontOfSize:12];
_commitTime.textColor = [UIColor colorWithHexString:@"0x999999"];
[self.contentView addSubview:_commitTime];
}
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (!_file) {
return;
}
if ([_file.mode isEqualToString:@"tree"]) {
self.leftIconView.image = [UIImage imageNamed:@"icon_code_tree"];
}else{
self.leftIconView.image = [UIImage imageNamed:@"icon_code_file"];
}
self.fileName.text = _file.name;
self.commitTime.attributedText = [self subTitleStr];
// self.commitTime.text = [[self subTitleStr] string];
}
- (NSAttributedString *)subTitleStr{
NSString *nameStr = _file.info.lastCommitter.name? _file.info.lastCommitter.name: @"...";
NSString *timeStr = _file.info.lastCommitDate? [_file.info.lastCommitDate stringTimesAgo]: @"...";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", nameStr, timeStr]];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x222222"]}
range:NSMakeRange(0, nameStr.length)];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x999999"]}
range:NSMakeRange(nameStr.length + 1, timeStr.length)];
return attrString;
}
+ (CGFloat)cellHeight{
return 60.0;
}
@end