IVTMyChatContentListTableViewCell.m
1.96 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
//
// IVTMyChatContentListTableViewCell.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/31.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMyChatContentListTableViewCell.h"
@interface IVTMyChatContentListTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *userAvatarImageView;
@property (weak, nonatomic) IBOutlet UIImageView *messageTextBg;
@property (weak, nonatomic) IBOutlet UILabel *messageText;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messageTextViewWidthConstraint;
@end
@implementation IVTMyChatContentListTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
UIImage *image = _messageTextBg.image;
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 8, 8, 10) resizingMode:UIImageResizingModeStretch];
_messageTextBg.image = image;
}
- (void)setUserAvatarUrl:(NSString *)userAvatarUrl{
_userAvatarUrl = userAvatarUrl;
[self.userAvatarImageView sd_setImageWithURL:[NSURL URLWithString:_userAvatarUrl] placeholderImage:[UIImage imageNamed:@"占位头像"]];
}
- (void)setContentText:(NSString *)contentText{
_contentText = contentText;
self.messageText.text = _contentText;
CGFloat width = [self getSizeForString:contentText font:[UIFont systemFontOfSize:14]].width + 1;
if (width < 180 - 15) {
_messageTextViewWidthConstraint.constant = width + 15;
}
else{
_messageTextViewWidthConstraint.constant = 180;
}
}
- (CGSize)getSizeForString:(NSString *)string font:(UIFont *)font{
NSDictionary *attributes = @{NSFontAttributeName:font};
CGSize labelSize = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
return labelSize;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end