// // TXShareLiveCellContentView.m // TUIChat // // Created by 王智 on 2023/8/10. // #import "TXShareLiveCellContentView.h" #import "Masonry.h" #import "UIImageView+WebCache.h" #import "TUIDefine.h" #define TXHexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] @interface TXShareLiveCellContentView () @property (nonatomic, strong) UIImageView *teacherAvatar; @property (nonatomic, strong) UILabel *descLabel; @property (nonatomic, strong) UILabel *waitDesc; @property (nonatomic, strong) UIView *liveView; @end @implementation TXShareLiveCellContentView + (instancetype)shareIntance { return [[TXShareLiveCellContentView alloc] init]; } - (instancetype)init { self = [super init]; if (self) { [self configUI]; } return self; } - (void)configUI { self.layer.cornerRadius = 10.0f; self.backgroundColor = [UIColor whiteColor]; UIView *avatarBg = [[UIView alloc] init]; avatarBg.backgroundColor = TXHexRGB(0xFF4347); avatarBg.layer.cornerRadius = 22.0f; [self addSubview:avatarBg]; [avatarBg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(14); make.top.mas_equalTo(self.mas_top).offset(11); make.width.height.mas_equalTo(44); }]; [avatarBg addSubview:self.teacherAvatar]; [self.teacherAvatar mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(avatarBg.mas_centerX); make.centerY.mas_equalTo(avatarBg.mas_centerY); make.width.height.mas_equalTo(42.0); }]; [self addSubview:self.liveView]; [self.liveView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(avatarBg.mas_centerX); make.centerY.mas_equalTo(avatarBg.mas_bottom); make.width.mas_equalTo(34); make.height.mas_equalTo(16); }]; UIView *colorView = [[UIView alloc] init]; colorView.backgroundColor = TXHexRGB(0xFF4347); colorView.layer.cornerRadius = 6.0f; [self.liveView addSubview:colorView]; [colorView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.liveView.mas_left).offset(2); make.right.mas_equalTo(self.liveView.mas_right).offset(-2); make.top.mas_equalTo(self.liveView.mas_top).offset(1); make.bottom.mas_equalTo(self.liveView.mas_bottom).offset(-1); }]; UILabel *liveLabel = [[UILabel alloc] init]; liveLabel.text = @"直播中"; liveLabel.textColor = TXHexRGB(0xffffff); liveLabel.font = [UIFont systemFontOfSize:8.0f]; [colorView addSubview:liveLabel]; [liveLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(colorView.mas_left).offset(2); make.right.mas_equalTo(colorView.mas_right).offset(-3); make.top.mas_equalTo(colorView.mas_top).offset(1); make.bottom.mas_equalTo(colorView.mas_bottom).offset(-1); }]; UILabel *liveHeadLable = [[UILabel alloc] init]; liveHeadLable.text = @"「正在直播」"; liveHeadLable.font = [UIFont systemFontOfSize:14.0f]; liveHeadLable.textColor = TXHexRGB(0x999999); [self addSubview:liveHeadLable]; [liveHeadLable mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(avatarBg.mas_right).offset(7); make.top.mas_equalTo(avatarBg.mas_top).offset(2); make.height.mas_equalTo(20); }]; [self addSubview:self.waitDesc]; [self.waitDesc mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(liveHeadLable.mas_left); make.top.mas_equalTo(liveHeadLable.mas_bottom).offset(1); make.height.mas_equalTo(20); make.right.mas_equalTo(self.mas_right).offset(-12); }]; [self addSubview:self.descLabel]; [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).offset(12); make.right.mas_equalTo(self.mas_right).offset(-12); make.top.mas_equalTo(avatarBg.mas_bottom).offset(8); }]; UIView *lineView = [[UIView alloc] init]; lineView.backgroundColor = TXHexRGB(0xF2F2F2); [self addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left); make.right.mas_equalTo(self.mas_right); make.height.mas_equalTo(1); make.top.mas_equalTo(self.descLabel.mas_bottom).offset(10); }]; UILabel *enterLabel = [[UILabel alloc] init]; enterLabel.text = @"进入直播间"; enterLabel.font = [UIFont systemFontOfSize:15.0f weight:UIFontWeightMedium]; enterLabel.textColor = TXHexRGB(0xFF4347); [self addSubview:enterLabel]; [enterLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.mas_centerX); make.height.mas_equalTo(21); make.top.mas_equalTo(lineView.mas_bottom).offset(7); }]; } - (void)configCellWithShareAvatar:(NSString *)avatar teacherName:(NSString *)teacherName liveDesc:(NSString *)desc { [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[self getUrlEndcodeString:avatar]] placeholderImage:[UIImage imageNamed:@"user_default_avatal"]]; self.waitDesc.text = [NSString stringWithFormat:@"%@在直播间等你哦~",[self returnNoNullStringWithString:teacherName]]; if (![self isEmptyString:desc]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:4];//调整行间距 NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:desc attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:TXHexRGB(0x666666)}]; self.descLabel.attributedText = attr; } else { self.descLabel.text = @""; } } - (NSString *)returnNoNullStringWithString:(NSString *)string { if (string == nil || string.length == 0) { return @""; } return string; } - (NSString *)getUrlEndcodeString:(NSString *)string { return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];; } - (BOOL)isEmptyString:(NSString *)str { if (str == nil || str.length == 0) { return YES; } return NO; } #pragma mark ------ live view - (UIImageView *)teacherAvatar { if (!_teacherAvatar) { _teacherAvatar = [[UIImageView alloc] init]; _teacherAvatar.contentMode = UIViewContentModeScaleAspectFill; _teacherAvatar.layer.cornerRadius = 21.0f; _teacherAvatar.layer.masksToBounds = YES; } return _teacherAvatar; } - (UIView *)liveView { if (!_liveView) { _liveView = [[UIView alloc] init]; _liveView.backgroundColor = [UIColor whiteColor]; _liveView.layer.cornerRadius = 8.0f; } return _liveView; } - (UILabel *)waitDesc { if (!_waitDesc) { _waitDesc = [[UILabel alloc] init]; _waitDesc.textColor = TXHexRGB(0x4A4A4A); _waitDesc.font = [UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium]; } return _waitDesc; } - (UILabel *)descLabel { if (!_descLabel) { _descLabel = [[UILabel alloc] init]; _descLabel.textColor = TXHexRGB(0x666666); _descLabel.font = [UIFont systemFontOfSize:14.0f weight:UIFontWeightRegular]; _descLabel.numberOfLines = 2; } return _descLabel; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end