-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathConversationCell.m
executable file
·93 lines (82 loc) · 3.13 KB
/
ConversationCell.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
//
// ConversationCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "ConversationCell.h"
@interface ConversationCell ()
@property (strong, nonatomic) UIImageView *userIconView;
@property (strong, nonatomic) UILabel *name, *msg, *time;
@end
@implementation ConversationCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
if (!_userIconView) {
_userIconView = [[YLImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([ConversationCell cellHeight]-48)/2, 48, 48)];
[_userIconView doCircleFrame];
[self.contentView addSubview:_userIconView];
}
if (!_name) {
_name = [[UILabel alloc] initWithFrame:CGRectMake(75, 8, 150, 25)];
_name.font = [UIFont systemFontOfSize:17];
_name.textColor = kColorDark3;
_name.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:_name];
}
if (!_time) {
_time = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width - 100-kPaddingLeftWidth, 8, 100, 25)];
_time.font = [UIFont systemFontOfSize:12];
_time.textColor = kColorDark7;
_time.textAlignment = NSTextAlignmentRight;
_time.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:_time];
}
if (!_msg) {
_msg = [[UILabel alloc] initWithFrame:CGRectMake(75, 30, kScreen_Width-75-30 -kPaddingLeftWidth, 25)];
_msg.font = [UIFont systemFontOfSize:15];
_msg.backgroundColor = [UIColor clearColor];
_msg.textColor = kColorDark7;
[self.contentView addSubview:_msg];
}
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
if (!_curPriMsg) {
return;
}
[_userIconView sd_setImageWithURL:[_curPriMsg.friend.avatar urlImageWithCodePathResizeToView:_userIconView] placeholderImage:kPlaceholderMonkeyRoundView(_userIconView)];
_name.text = _curPriMsg.friend.name;
_time.text = [_curPriMsg.created_at stringDisplay_MMdd];
_msg.textColor = kColorDark7;
NSMutableString *textMsg = [[NSMutableString alloc] initWithString:_curPriMsg.content];
if (_curPriMsg.hasMedia) {
[textMsg appendString:@"[图片]"];
}
if ([_curPriMsg isVoice]) {
[textMsg setString:@"[语音]"];
if (_curPriMsg.played.intValue == 0) {
_msg.textColor = kColorBrandBlue;
}
}
_msg.text = textMsg;
NSString *badgeTip = @"";
if (_curPriMsg.unreadCount && _curPriMsg.unreadCount.integerValue > 0) {
if (_curPriMsg.unreadCount.integerValue > 99) {
badgeTip = @"99+";
}else{
badgeTip = _curPriMsg.unreadCount.stringValue;
}
}
[self.contentView addBadgeTip:badgeTip withCenterPosition:CGPointMake(kScreen_Width-25, CGRectGetMaxY(_time.frame) +10)];
}
+ (CGFloat)cellHeight{
return 61;
}
@end