YH_BarrageJoinCell.m
1.92 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
//
// YH_BarrageJoinCell.m
// Yoho
//
// Created by Arthur on 16/6/14.
// Copyright © 2016年 YOHO. All rights reserved.
//
#import "YH_BarrageJoinCell.h"
#define kUserNameMaxLenght 15
#define kUserNameWidth (200 * kScreenPointScale)
#define kFontName [UIFont systemFontOfSize:15.0f]
@interface YH_BarrageJoinCell()
@property (strong, nonatomic) UILabel *nameLabel;
@end
@implementation YH_BarrageJoinCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self addSubview:self.nameLabel];
[self setBackgroundColor:[UIColor clearColor]];
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return self;
}
- (void)setMsgModel:(YH_BarrageMsgModel *)msgModel
{
_msgModel = msgModel;
NSString *name = msgModel.userName;
if (name.length > kUserNameMaxLenght) {
name = [name substringToIndex:kUserNameMaxLenght];
name = [name stringByAppendingString:@"..."];
}
self.nameLabel.text = [NSString stringWithFormat:@" @%@加入了 ", name];
// CGFloat nameWidth = [self.nameLabel.text boundingRectWithSize:CGSizeMake(kUserNameWidth, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : kFontName} context:nil].size.width;
// [self.nameLabel setWidth:nameWidth];
}
- (UILabel *)nameLabel
{
if (_nameLabel == nil) {
_nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, 200, 20)];
[_nameLabel setFont:kFontName];
[_nameLabel setTextColor:[UIColor blackColor]];
[_nameLabel setTextAlignment:NSTextAlignmentLeft];
[_nameLabel.layer setCornerRadius:6.0f];
[_nameLabel setClipsToBounds:YES];
[_nameLabel setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.7]];
}
return _nameLabel;
}
@end