12
12
#import " Login.h"
13
13
14
14
@interface TweetDetailCommentCell ()
15
- @property (strong , nonatomic ) UILabel *timeLabel;
15
+ // @property (strong, nonatomic) UILabel *timeLabel;
16
+
17
+ @property (strong , nonatomic ) UILabel *userNameLabel, *timeLabel;
18
+ @property (strong , nonatomic ) UIImageView *timeClockIconView;
19
+
16
20
@end
17
21
18
22
@implementation TweetDetailCommentCell
@@ -22,29 +26,35 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
22
26
self = [super initWithStyle: style reuseIdentifier: reuseIdentifier];
23
27
if (self) {
24
28
// Initialization code
25
- CGFloat curBottomY = 10 ;
26
- if (!_ownerIconView) {
27
- _ownerIconView = [[UITapImageView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , curBottomY, 33 , 33 )];
28
- [_ownerIconView doCircleFrame ];
29
- [self .contentView addSubview: _ownerIconView];
30
- }
31
- CGFloat curWidth = kScreen_Width - 40 - 2 *kPaddingLeftWidth ;
32
29
if (!_contentLabel) {
33
- _contentLabel = [[UITTTAttributedLabel alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth + 40 , curBottomY, curWidth , 30 )];
30
+ _contentLabel = [[UITTTAttributedLabel alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 15 , kScreen_Width - 2 * kPaddingLeftWidth , 30 )];
34
31
_contentLabel.numberOfLines = 0 ;
35
- _contentLabel.textColor = kColor222 ;
32
+ _contentLabel.textColor = kColorDark4 ;
36
33
_contentLabel.font = kTweetDetailCommentCell_FontContent ;
37
34
_contentLabel.linkAttributes = kLinkAttributes ;
38
35
_contentLabel.activeLinkAttributes = kLinkAttributesActive ;
39
36
[self .contentView addSubview: _contentLabel];
40
37
}
41
- CGFloat commentBtnWidth = 40 ;
38
+ if (!_userNameLabel) {
39
+ _userNameLabel = [[UILabel alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , 0 , 150 , 15 )];
40
+ _userNameLabel.backgroundColor = [UIColor clearColor ];
41
+ _userNameLabel.font = [UIFont boldSystemFontOfSize: 12 ];
42
+ _userNameLabel.textColor = kColorDark7 ;
43
+ [self .contentView addSubview: _userNameLabel];
44
+ }
42
45
if (!_timeLabel) {
43
- _timeLabel = [[UILabel alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth + 40 , 0 , curWidth- commentBtnWidth, 20 )];
44
- _timeLabel.textColor = kColor999 ;
46
+ _timeLabel = [[UILabel alloc ] initWithFrame: CGRectMake (75 , 0 , 80 , 15 )];
47
+ _timeLabel.backgroundColor = [UIColor clearColor ] ;
45
48
_timeLabel.font = [UIFont systemFontOfSize: 12 ];
49
+ _timeLabel.textColor = kColorDark7 ;
46
50
[self .contentView addSubview: _timeLabel];
47
51
}
52
+ if (!_timeClockIconView) {
53
+ _timeClockIconView = [[UIImageView alloc ] initWithFrame: CGRectMake (60 , 0 , 15 , 15 )];
54
+ _timeClockIconView.contentMode = UIViewContentModeCenter;
55
+ _timeClockIconView.image = [UIImage imageNamed: @" time_clock_icon" ];
56
+ [self .contentView addSubview: _timeClockIconView];
57
+ }
48
58
}
49
59
return self;
50
60
}
@@ -62,10 +72,8 @@ - (void)layoutSubviews{
62
72
if (!_toComment) {
63
73
return ;
64
74
}
65
- CGFloat curBottomY = 10 ;
66
- CGFloat curWidth = kScreen_Width - 40 - 2 *kPaddingLeftWidth ;
67
- [_ownerIconView sd_setImageWithURL: [_toComment.owner.avatar urlImageWithCodePathResizeToView: _ownerIconView] placeholderImage: kPlaceholderMonkeyRoundView (_ownerIconView)];
68
-
75
+ CGFloat curBottomY = 15 ;
76
+ CGFloat curWidth = kScreen_Width - 2 *kPaddingLeftWidth ;
69
77
[_contentLabel setWidth: curWidth];
70
78
_contentLabel.text = _toComment.content ;
71
79
[_contentLabel sizeToFit ];
@@ -76,9 +84,23 @@ - (void)layoutSubviews{
76
84
}
77
85
}
78
86
79
- curBottomY += [_toComment.content getHeightWithFont: kTweetDetailCommentCell_FontContent constrainedToSize: CGSizeMake (curWidth, CGFLOAT_MAX)] + 5 ;
80
- [_timeLabel setY: curBottomY];
81
- _timeLabel.text = [NSString stringWithFormat: @" %@ 发布于 %@ " , _toComment.owner.name, [_toComment.created_at stringDisplay_HHmm ]];
87
+ curBottomY += [_toComment.content getHeightWithFont: kTweetDetailCommentCell_FontContent constrainedToSize: CGSizeMake (curWidth, CGFLOAT_MAX)] + 10 ;
88
+
89
+
90
+ _userNameLabel.text = _toComment.owner .name ;
91
+ _timeLabel.text = [_toComment.created_at stringDisplay_HHmm ];
92
+ [_userNameLabel setY: curBottomY];
93
+ [_userNameLabel sizeToFit ];
94
+
95
+ CGRect frame = _timeClockIconView.frame ;
96
+ frame.origin .y = curBottomY;
97
+ frame.origin .x = 10 + CGRectGetMaxX (_userNameLabel.frame );
98
+ _timeClockIconView.frame = frame;
99
+
100
+ frame.origin .x += 5 + CGRectGetWidth (_timeClockIconView.frame );
101
+ frame.size = _timeLabel.frame .size ;
102
+ _timeLabel.frame = frame;
103
+ [_timeLabel sizeToFit ];
82
104
}
83
105
84
106
- (void )commentBtnClicked : (id )sender {
@@ -92,8 +114,8 @@ + (CGFloat)cellHeightWithObj:(id)obj{
92
114
CGFloat cellHeight = 0 ;
93
115
if ([obj isKindOfClass: [Comment class ]]) {
94
116
Comment *toComment = (Comment *)obj;
95
- CGFloat curWidth = kScreen_Width - 40 - 2 *kPaddingLeftWidth ;
96
- cellHeight += 10 +[toComment.content getHeightWithFont: kTweetDetailCommentCell_FontContent constrainedToSize: CGSizeMake (curWidth, CGFLOAT_MAX)] + 5 + 20 + 10 ;
117
+ CGFloat curWidth = kScreen_Width - 2 *kPaddingLeftWidth ;
118
+ cellHeight += 15 +[toComment.content getHeightWithFont: kTweetDetailCommentCell_FontContent constrainedToSize: CGSizeMake (curWidth, CGFLOAT_MAX)] + 10 + 15 + 15 ;
97
119
}
98
120
return cellHeight;
99
121
}
0 commit comments