GiGaMaskTime/GIGA/Modules/Mask/View/GiGaCommentView.m

115 lines
3.6 KiB
Objective-C

//
// GiGaCommentView.m
// LXAnimationTest
//
// Created by lianxiang on 2018/8/14.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//弹幕评论视图
#import "GiGaCommentView.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "NSString+Unicode.h"
@interface GiGaCommentView()
@property(nonatomic,strong) UILabel *userName;
@property(nonatomic,strong) UIImageView *userAvtar;
@property(nonatomic,strong) UILabel *msg;
@end
@implementation GiGaCommentView
-(instancetype)initWithMsgModel:(GiGaCommentModel *)model height:(CGFloat)height{
if (self = [super init]) {
self.frame = CGRectMake(0, 0, 0, height);
_msgModel = model;
//self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
//self.backgroundColor = [UIColor redColor];
[self initUI];
}
return self;
}
-(void)layoutIfNeeded{
}
- (void)layoutSubviews{
}
-(void)initUI{
// UIImageView *avatar = [[UIImageView alloc] init];
// avatar.layer.masksToBounds = YES;
// avatar.layer.cornerRadius = 15;
// [self addSubview:avatar];
// [avatar sd_setImageWithURL:[NSURL URLWithString:_msgModel.sendUserHeadImg] placeholderImage:[UIImage imageNamed:@"nav_circle_avatar"]];
// self.userAvtar = avatar;
// [self.userAvtar mas_makeConstraints:^(MASConstraintMaker *make) {
// make.width.mas_equalTo(30);
// make.height.mas_equalTo(30);
// make.left.mas_equalTo(self.mas_left).mas_offset(3);
// make.top.mas_equalTo(self.mas_top).mas_offset(3);
//
// }];
UILabel *namelabel = [[UILabel alloc] init];
namelabel.font = GIGA_TEXTFONTBOLD(15);
namelabel.textColor = [UIColor whiteColor];
//namelabel.frame= CGRectMake(CGRectGetMaxX(avatar.frame) + 5, 4, namelabel.frame.size.width, namelabel.frame.size.height);
namelabel.text = @"用户名:";
if (_msgModel.sendUserName && _msgModel.sendUserName.length > 0) {
namelabel.text = [NSString stringWithFormat:@"%@:",_msgModel.sendUserName];
}
[namelabel sizeToFit];
self.userName = namelabel;
[self addSubview:self.userName];
// [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
//
// make.left.mas_equalTo(self.userAvtar.mas_right).mas_offset(3);
// make.top.mas_equalTo(self.mas_top).mas_offset(10);
//
// }];
[self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).offset(3);
make.centerY.mas_equalTo(self.mas_centerY);
}];
UILabel *msglabel = [[UILabel alloc] init];
msglabel.font = GIGA_TEXTFONTMEDIUM(13);
msglabel.textColor = [UIColor whiteColor];
msglabel.text = @"信息内容";
if (_msgModel.content && _msgModel.content.length > 0) {
msglabel.text = [_msgModel.content replaceUnicode:_msgModel.content];
}
self.msg = msglabel;
[msglabel sizeToFit];
[self addSubview:self.msg];
// [self.msg mas_makeConstraints:^(MASConstraintMaker *make) {
//
// make.top.mas_equalTo(self.userAvtar.mas_bottom).mas_offset(3);
// make.left.mas_equalTo(self.mas_left).mas_offset(5);
//
// }];
[self.msg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(namelabel.mas_right).offset(2);
make.centerY.mas_equalTo(self.mas_centerY);
}];
[self layoutIfNeeded];
// float width = msglabel.frame.size.width > namelabel.frame.size.width ? msglabel.frame.size.width:namelabel.frame.size.width ;
float width = msglabel.frame.size.width + namelabel.frame.size.width;
self.frame = CGRectMake(0, 0, width, self.frame.size.height);
}
@end