forked from cubewang/NewsReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentCell.m
152 lines (111 loc) · 4.16 KB
/
CommentCell.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// CommentCell.m
// EnglishFun
//
// Created by curer on 12-1-9.
// Copyright 2012 iKnow Team. All rights reserved.
//
#import "CommentCell.h"
#import "Comment.h"
#define AVATAR_HEIGHT 30
@implementation CommentCell
@synthesize userNameLabel;
@synthesize commentLabel;
@synthesize dateLabel;
@synthesize userAvatarImageView;
+ (int)heightForCell:(Comment *)comment
{
CGSize s = [comment.Content sizeWithFont:ZBSTYLE_font
constrainedToSize:CGSizeMake(SCREEN_WIDTH - AVATAR_HEIGHT - kTableCellSmallMargin * 3, MAXFLOAT)
lineBreakMode:UILineBreakModeWordWrap];
return s.height + 2 * AVATAR_HEIGHT;
}
- (void)awakeFromNib
{
// Initialization code.
userNameLabel.font = ZBSTYLE_font;
[userNameLabel setBackgroundColor:[UIColor clearColor]];
dateLabel.font = ZBSTYLE_font;
[dateLabel setBackgroundColor:[UIColor clearColor]];
dateLabel.textColor = ZBSTYLE_tableSubTextColor;
commentLabel.font = ZBSTYLE_font;
commentLabel.numberOfLines = 0;
[commentLabel setBackgroundColor:[UIColor clearColor]];
CALayer *layer = [userAvatarImageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:5];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
- (void)setDataSource:(Comment *)comment;
{
if (comment.MemberName == nil || [comment.MemberName length] == 0) {
userNameLabel.text = DEFAULT_NAME;
} else {
userNameLabel.text = comment.MemberName;
}
if (comment.IsOfficialComment) {
userNameLabel.textColor = OFFICIAL_COLOR;
}
else {
userNameLabel.textColor = ZBSTYLE_textColor;
}
[userAvatarImageView setImageWithURL:comment.avatarImagePath
placeholderImage:[UIImage imageNamed:@"Avatar1.png"]];
NSRange range = [comment.PublishedDate rangeOfString:@" "];
range.length = range.location;
range.location = 0;
dateLabel.text = [comment.PublishedDate substringWithRange:range];
if ([comment.UserId length] > 0)
{
self.backgroundView = [[[UIView alloc] init] autorelease];
self.backgroundView.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0];
}
commentLabel.text = comment.Content;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[userNameLabel release];
[commentLabel release];
[dateLabel release];
[userAvatarImageView release];
[super dealloc];
}
- (void)prepareForReuse {
[super prepareForReuse];
userNameLabel.text = nil;
commentLabel.text = nil;
dateLabel.text = nil;
userAvatarImageView.image = nil;
}
- (void)layoutSubviews
{
[super layoutSubviews];
int height = AVATAR_HEIGHT;
CGRect avatarRect = CGRectMake(kTableCellSmallMargin, kTableCellSmallMargin, height, height);
self.userAvatarImageView.frame = avatarRect;
CGRect dateRect = CGRectMake(SCREEN_WIDTH - 100, kTableCellSmallMargin, 100, 16);
self.dateLabel.frame = dateRect;
CGRect nameRect = CGRectMake(avatarRect.size.width + 2 * kTableCellSmallMargin, kTableCellSmallMargin, 100, 16);
self.userNameLabel.frame = nameRect;
CGSize s = [commentLabel.text sizeWithFont:ZBSTYLE_font
constrainedToSize:CGSizeMake(SCREEN_WIDTH - nameRect.origin.x - kTableCellSmallMargin, MAXFLOAT)
lineBreakMode:UILineBreakModeWordWrap];
CGRect
commentRect = CGRectMake(nameRect.origin.x,
avatarRect.origin.y + avatarRect.size.height + kTableCellSmallMargin,
s.width,
s.height);
commentLabel.frame = commentRect;
CGRect cellRect = self.frame;
cellRect.size.height = commentRect.size.height + 60;
self.frame = cellRect;
}
@end