YH_BarrageJoinCell.m 1.92 KB
//
//  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.4]];
    }
    
    return _nameLabel;
}


@end