// // YOUPAILZLiveItemCell.m // TIANYAN // // Created by CY on 2021/5/19. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZLiveItemCell.h" #import "YYAnimatedImageView.h" @interface YOUPAILZLiveItemCell() @property (nonatomic, weak) UIImageView *youpaipavatarImgV; // 头像 @property (nonatomic, weak) UIButton *youpaipleftTopBtn; // 左上角 @property (nonatomic, weak) YYAnimatedImageView *youpaipiconAnimationImgV; @property (nonatomic, weak) UIImageView *youpaipiconImgV; @property (nonatomic, weak) UILabel *youpaiptextL; @property (nonatomic, weak) UILabel *youpaipnicknameL; // 昵称 @property (nonatomic, weak) UIImageView *youpaipiconImgV1; /* 标题 */ @property (strong, nonatomic) UILabel *youpaiptitleLabel; @end @implementation YOUPAILZLiveItemCell - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self youpaifinitUI]; self.backgroundColor = [UIColor clearColor]; } return self; } - (void)youpaifinitUI{ UIImageView *youpaipavatarImgV = [[UIImageView alloc] init]; youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill; // youpaipavatarImgV.layer.cornerRadius = 8.0f; youpaipavatarImgV.clipsToBounds = YES; [self.contentView addSubview:youpaipavatarImgV]; self.youpaipavatarImgV = youpaipavatarImgV; [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.right.offset(0.0f); }]; UIButton *youpaipleftTopBtn = [UIButton buttonWithType:UIButtonTypeCustom]; youpaipleftTopBtn.frame = CGRectMake(0, 0, 56.0f, 20.0f); [LCTools clipCorner:UIRectCornerBottomRight View:youpaipleftTopBtn size:CGSizeMake(8.0f, 8.0f)]; youpaipleftTopBtn.userInteractionEnabled = NO; [youpaipavatarImgV addSubview:youpaipleftTopBtn]; self.youpaipleftTopBtn = youpaipleftTopBtn; [youpaipleftTopBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.offset(0.0f); make.size.mas_offset(CGSizeMake(56.0f, 20.0f)); }]; youpaipleftTopBtn.hidden = YES; YYAnimatedImageView *youpaipiconAnimationImgV = [[YYAnimatedImageView alloc] init]; youpaipiconAnimationImgV.hidden = YES; [youpaipleftTopBtn addSubview:youpaipiconAnimationImgV]; self.youpaipiconAnimationImgV = youpaipiconAnimationImgV; [youpaipiconAnimationImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(5.0f); make.centerY.equalTo(youpaipleftTopBtn.mas_centerY); make.size.mas_offset(CGSizeMake(14.0f, 14.0f)); }]; UIImageView *youpaipiconImgV = [[UIImageView alloc] init]; youpaipiconImgV.hidden = YES; [youpaipleftTopBtn addSubview:youpaipiconImgV]; self.youpaipiconImgV = youpaipiconImgV; [youpaipiconImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(8.0f); make.centerY.equalTo(youpaipleftTopBtn.mas_centerY); make.size.mas_offset(CGSizeMake(14.0f, 14.0f)); }]; UILabel *youpaiptextL = [[UILabel alloc] init]; youpaiptextL.font = LCFont(10.0f); youpaiptextL.textColor = [UIColor whiteColor]; [youpaipleftTopBtn addSubview:youpaiptextL]; self.youpaiptextL = youpaiptextL; [youpaiptextL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipiconImgV.mas_right).offset(2.0f); make.centerY.equalTo(youpaipleftTopBtn.mas_centerY); }]; UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.mj_w, 49.0f)]; CAGradientLayer *gradientLayerBot = [LCTools getGradientLayerWithSize:footerV.mj_size twoColors:@[[[UIColor blackColor] colorWithAlphaComponent:0.0f],[[UIColor blackColor] colorWithAlphaComponent:0.3f]] gradientType:GradientTopToBottom]; [footerV.layer addSublayer:gradientLayerBot]; [youpaipavatarImgV addSubview:footerV]; [footerV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.height.offset(49.0f); }]; UILabel *youpaipnicknameL = [[UILabel alloc] init]; youpaipnicknameL.textColor = [UIColor whiteColor]; youpaipnicknameL.font = LCFont(16); [footerV addSubview:youpaipnicknameL]; self.youpaipnicknameL = youpaipnicknameL; [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10.0f); make.top.mas_equalTo(7.0f); make.right.mas_equalTo(-10.0f); }]; youpaipnicknameL.lineBreakMode =NSLineBreakByTruncatingTail; //标题 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.textColor = [UIColor whiteColor]; titleLabel.font = LCFont(12); [footerV addSubview:titleLabel]; self.youpaiptitleLabel = titleLabel; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10.0f); make.right.mas_equalTo(-10.0f); make.top.mas_equalTo(youpaipnicknameL.mas_bottom).offset(5); }]; titleLabel.lineBreakMode =NSLineBreakByTruncatingTail; UIImageView *iconImgV1 = [[UIImageView alloc] init]; iconImgV1.image = [UIImage imageNamed:@"vqu_images_L_live_zhibozhong"]; iconImgV1.hidden = YES; [footerV addSubview:iconImgV1]; self.youpaipiconImgV1 = iconImgV1; [iconImgV1 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-8.0f); make.top.offset(14.0f); make.size.mas_offset(CGSizeMake(14.0f, 14.0f)); }]; } - (void)youpaifreloadWithModel:(YOUPAILZLiveListItemModel *)model style:(LZLiveItemCellStyle)style index:(NSInteger)index{ self.youpaipiconAnimationImgV.hidden = YES; self.youpaipiconImgV.hidden = YES; // self.titleLabel.text = model.live_name; [self youpaifsetupShadowWithText:model.youpaiplive_name view:self.youpaiptitleLabel]; if (model.youpaipanchor_name.length>0&&model.youpaiplive_name.length<=0) { self.youpaiptitleLabel.hidden = YES; [self.youpaipnicknameL mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10.0f); make.right.mas_equalTo(-10.0f); make.bottom.mas_equalTo(-10); }]; }else if (model.youpaiplive_name.length>0&&model.youpaipanchor_name.length<=0){ self.youpaipnicknameL.hidden = YES; [self.youpaiptitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10.0f); make.right.mas_equalTo(-10.0f); make.bottom.mas_equalTo(-10); }]; }else{ self.youpaiptitleLabel.hidden = NO; self.youpaipnicknameL.hidden = NO; } if (style == LZLiveItemCellStyleWithDefault) { // 默认样式 UIImage *bgImage = [LCTools ColorImage:CGSizeMake(56.0f, 20.0f) FromColors:@[HexColorFromRGB(0xFF2ADD),HexColorFromRGB(0xFF6769)] ByGradientType:GradientLeftToRight]; [self.youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateNormal]; [self.youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted]; self.youpaipiconAnimationImgV.image = self.youpaipanimationImage; self.youpaiptextL.text = @"直播中"; self.youpaipiconAnimationImgV.hidden = NO; [self.youpaiptextL mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.youpaipiconAnimationImgV.mas_right).offset(2.0f); make.centerY.equalTo(self.youpaipleftTopBtn.mas_centerY); }]; }else{ // 排名样式 self.youpaipleftTopBtn.hidden = YES; UIImage *bgImage = [LCTools ColorImage:CGSizeMake(56.0f, 20.0f) FromColors:@[HexColorFromRGB(0xFFB64C),HexColorFromRGB(0xFF6767)] ByGradientType:GradientLeftToRight]; [self.youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateNormal]; [self.youpaipleftTopBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted]; self.youpaipiconImgV.hidden = NO; self.youpaipiconImgV1.hidden = NO; self.youpaipiconImgV.image = [UIImage imageNamed:@"vqu_images_L_live_hot"]; if(index < 5){ self.youpaiptextL.text = [NSString stringWithFormat:@"No.%ld",index + 1]; self.youpaipleftTopBtn.hidden = YES; }else{ self.youpaiptextL.text = @""; } [self.youpaiptextL mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.youpaipiconImgV.mas_right).offset(2.0f); make.centerY.equalTo(self.youpaipleftTopBtn.mas_centerY); }]; } [self.youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipcover_img]]; [self youpaifsetupShadowWithText:model.youpaipanchor_name view:self.youpaipnicknameL]; } - (void)youpaifsetupShadowWithText:(NSString *)text view:(UILabel *)view{ NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text]; NSShadow *shadow = [[NSShadow alloc]init]; // shadow.shadowBlurRadius = 1.0; shadow.shadowOffset = CGSizeMake(1, 1.5f); shadow.shadowColor = [HexColorFromRGB(0x000000) colorWithAlphaComponent:0.2f]; [attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, text.length)]; view.attributedText = attributedString; } @end