forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRPRListCell.m
More file actions
101 lines (92 loc) · 4.46 KB
/
MRPRListCell.m
File metadata and controls
101 lines (92 loc) · 4.46 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// MRPRListCell.m
// Coding_iOS
//
// Created by Ease on 15/5/29.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define kMRPRListCell_UserWidth 33.0
#import "MRPRListCell.h"
@interface MRPRListCell ()
@property (strong, nonatomic) UIImageView *imgView;
@property (strong, nonatomic) UILabel *titleLabel, *subTitleLabel;
@end
@implementation MRPRListCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
self.backgroundColor = kColorTableBG;
if (!_imgView) {
_imgView = [UIImageView new];
_imgView.layer.masksToBounds = YES;
_imgView.layer.cornerRadius = kMRPRListCell_UserWidth/2;
_imgView.layer.borderWidth = 0.5;
_imgView.layer.borderColor = [UIColor colorWithHexString:@"0xdddddd"].CGColor;
[self.contentView addSubview:_imgView];
[_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(kMRPRListCell_UserWidth, kMRPRListCell_UserWidth));
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.centerY.equalTo(self.contentView);
}];
}
if (!_titleLabel) {
_titleLabel = [UILabel new];
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_imgView.mas_right).offset(12);
make.right.equalTo(self.contentView);
make.top.equalTo(self.contentView).offset(13);
make.height.mas_equalTo(20);
}];
}
if (!_subTitleLabel) {
_subTitleLabel = [UILabel new];
[self.contentView addSubview:_subTitleLabel];
[_subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.equalTo(_titleLabel);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-13);
}];
}
}
return self;
}
- (void)setCurMRPR:(MRPR *)curMRPR{
_curMRPR = curMRPR;
if (!_curMRPR) {
return;
}
[_imgView sd_setImageWithURL:[_curMRPR.author.avatar urlImageWithCodePathResize:2*kMRPRListCell_UserWidth] placeholderImage:kPlaceholderMonkeyRoundWidth(2*kMRPRListCell_UserWidth)];
_titleLabel.attributedText = [self attributeTitle];
_subTitleLabel.attributedText = [self attributeTail];
}
- (NSAttributedString *)attributeTitle{
NSString *iidStr = [NSString stringWithFormat:@"#%@", _curMRPR.iid.stringValue? _curMRPR.iid.stringValue: @""];
NSString *titleStr = _curMRPR.title? _curMRPR.title: @"";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", iidStr, titleStr]];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:14],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x4E90BF"]}
range:NSMakeRange(0, iidStr.length)];
[attrString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:14],
NSForegroundColorAttributeName : [UIColor colorWithHexString:@"0x222222"]}
range:NSMakeRange(iidStr.length + 1, titleStr.length)];
return attrString;
}
- (NSAttributedString *)attributeTail{
NSString *nameStr = _curMRPR.author.name? _curMRPR.author.name: @"";
NSString *timeStr = _curMRPR.created_at? [_curMRPR.created_at stringDisplay_HHmm]: @"";
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 70.0;
}
@end