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

95 lines
3.1 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"
@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.image = [UIImage imageNamed:@"home_login_qq_color"];
//avatar.frame = CGRectMake(3, 3, self.frame.size.height - 6, self.frame.size.height - 6);
avatar.layer.masksToBounds = YES;
avatar.layer.cornerRadius = 15;
[self addSubview:avatar];
avatar.image = [UIImage imageNamed:_msgModel.userAvatar];
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 = [UIFont systemFontOfSize:14];
namelabel.textColor = [UIColor blackColor];
//namelabel.frame= CGRectMake(CGRectGetMaxX(avatar.frame) + 5, 4, namelabel.frame.size.width, namelabel.frame.size.height);
namelabel.text = _msgModel.userName;
[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);
}];
UILabel *msglabel = [[UILabel alloc] init];
msglabel.font = [UIFont systemFontOfSize:13];
msglabel.textColor = [UIColor blackColor];
//msglabel.frame= CGRectMake(namelabel.frame.origin.x, CGRectGetMaxY(avatar.frame) - msglabel.frame.size.height - namelabel.frame.origin.y, msglabel.frame.size.width, msglabel.frame.size.height);
msglabel.text = _msgModel.msg;
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);
}];
float width = msglabel.frame.size.width > namelabel.frame.size.width ? msglabel.frame.size.width:namelabel.frame.size.width ;
self.frame = CGRectMake(0, 0, namelabel.frame.origin.x + 10 + width, self.frame.size.height);
}
@end