// // YOUPAIHRChatRoomHomeCell.m // VQU // // Created by xiaohaoran on 2021/11/2. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRChatRoomHomeCell.h" #import "YYAnimatedImageView.h" #import "YYImage.h" #import "LOTAnimationView.h" @interface YOUPAIHRChatRoomHomeCell () @property (nonatomic,strong)UIImageView *youpaipimageV;//头像 @property(nonatomic,strong)UILabel *youpaiptitleLabel; @property (nonatomic, weak) LOTAnimationView *youpaipiconAnimationImgV; @property (nonatomic, weak) UIButton *youpaiprightBottomBtn; // 右下角 @property(nonatomic,strong)UIButton *youpaiphomeLockBtn;//房间锁 @property(nonatomic ,strong)UILabel *youpaippeopleLabel; @property(nonatomic ,strong)UIView *youpaipfooterV; @property(nonatomic,strong)UIButton *youpaipmyHomeBtn; @property(nonatomic,strong)UIImageView *youpaipiconImageView; @property (nonatomic,strong)NSMutableArray *youpaipmemberAvatars; @property (nonatomic,weak)UIView *youpaipmemberAvatarBgV; @end @implementation YOUPAIHRChatRoomHomeCell -(instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self youpaifsetSubView]; } return self; } -(void)youpaifsetSubView{ // self.contentView.backgroundColor = [LCTools getBkgRandomColor]; self.contentView.layer.cornerRadius = 5; self.contentView.layer.masksToBounds = YES; //头像 UIImageView *iconImage = [[UIImageView alloc] init]; [self.contentView addSubview:iconImage]; self.youpaipimageV = iconImage; [self.youpaipimageV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(169); }]; self.youpaipimageV.userInteractionEnabled = YES; self.youpaipimageV.layer.cornerRadius = 5; self.youpaipimageV.contentMode = UIViewContentModeScaleAspectFill; self.youpaipimageV.clipsToBounds = YES; //我的房间(类型,点唱,女神) UIButton *youpaipmyHomeBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 32, 18)]; self.youpaipmyHomeBtn = youpaipmyHomeBtn; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomRight View:youpaipmyHomeBtn size:CGSizeMake(4, 4)]; [self.youpaipimageV addSubview:youpaipmyHomeBtn]; [youpaipmyHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; youpaipmyHomeBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [youpaipmyHomeBtn setBackgroundColor:HexColorFromRGBA(0x000000, 0.38)]; //房间锁 UIButton *youpaiphomeLockBtn = [UIButton new]; self.youpaiphomeLockBtn = youpaiphomeLockBtn; [self.youpaipimageV addSubview:youpaiphomeLockBtn]; [youpaiphomeLockBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.size.mas_equalTo(CGSizeMake(35, 35)); }]; youpaiphomeLockBtn.hidden = YES; [youpaiphomeLockBtn setImage:[UIImage imageNamed:@"vqu_images_chatroom_lock"] forState:UIControlStateNormal]; //阴影 UIView *youpaipfooterV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.mj_w, 49.0f)]; self.youpaipfooterV = youpaipfooterV; CAGradientLayer *gradientLayerBot = [LCTools getGradientLayerWithSize:youpaipfooterV.mj_size twoColors:@[[[UIColor blackColor] colorWithAlphaComponent:0.0f],[[UIColor blackColor] colorWithAlphaComponent:0.3f]] gradientType:GradientTopToBottom]; [youpaipfooterV.layer addSublayer:gradientLayerBot]; [self.youpaipimageV addSubview:youpaipfooterV]; [youpaipfooterV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.height.offset(34.0f); }]; UIButton *youpaiprightBottomBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.youpaiprightBottomBtn = youpaiprightBottomBtn; youpaiprightBottomBtn.frame = CGRectMake(0, 0, 56.0f, 20.0f); [LCTools clipCorner:UIRectCornerBottomRight View:youpaiprightBottomBtn size:CGSizeMake(8.0f, 8.0f)]; [youpaipfooterV addSubview:youpaiprightBottomBtn]; self.youpaiprightBottomBtn = youpaiprightBottomBtn; [youpaiprightBottomBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(0.0f); make.centerY.mas_equalTo(0); make.size.mas_offset(CGSizeMake(56+5+4.5+20, 20.0f)); }]; //人数 UILabel *youpaippeopleLabel = [UILabel new]; self.youpaippeopleLabel = youpaippeopleLabel; [youpaipfooterV addSubview:youpaippeopleLabel]; [youpaippeopleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-5); make.centerY.mas_equalTo(0); make.width.mas_equalTo(56+5); }]; youpaippeopleLabel.textColor = [UIColor whiteColor]; youpaippeopleLabel.font = [UIFont systemFontOfSize:12]; //动画 LOTAnimationView *youpaipiconAnimationImgV = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:@"ic_chatroom_part" ofType:@"json"]]; [youpaiprightBottomBtn addSubview:youpaipiconAnimationImgV]; // talkingAnimationView.frame = CGRectMake(0.0f, 0.0f, self.mj_w * 1.7f, self.mj_h * 1.7f); youpaipiconAnimationImgV.loopAnimation = YES; youpaipiconAnimationImgV.contentMode = UIViewContentModeScaleAspectFill; [youpaipiconAnimationImgV play]; self.youpaipiconAnimationImgV = youpaipiconAnimationImgV; [youpaipiconAnimationImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(youpaippeopleLabel.mas_left).offset(-4.5); make.centerY.equalTo(youpaippeopleLabel).offset(-2); make.size.mas_offset(CGSizeMake(16.0f, 14.0f)); }]; //bottomView UIView *bottomView = [UIView new]; [self.contentView addSubview:bottomView]; [bottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(iconImage.mas_bottom); make.bottom.mas_equalTo(0); }]; bottomView.backgroundColor = LCBkgColor; //title UILabel *titleLabel = [UILabel new]; self.youpaiptitleLabel = titleLabel; [bottomView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(5); make.right.mas_equalTo(0); make.centerY.mas_equalTo(0); }]; titleLabel.text = @"快来签收你的小可爱"; titleLabel.textColor = [UIColor whiteColor]; titleLabel.font = [UIFont systemFontOfSize:14]; //3个头像 UIButton *threeIconBgBtn = [UIButton new]; [youpaipfooterV addSubview:threeIconBgBtn]; [threeIconBgBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(0); make.width.mas_equalTo(49+24); }]; UIView *youpaipmemberAvatarBgV = [[UIView alloc] init]; [threeIconBgBtn addSubview:youpaipmemberAvatarBgV]; self.youpaipmemberAvatarBgV = youpaipmemberAvatarBgV; [youpaipmemberAvatarBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.centerY.mas_equalTo(0); make.width.offset(0.0f); make.height.offset(24.0f); }]; } - (void)setYoupaiphomeListModel:(YOUPAIHRChatRoomSubDetailModel *)youpaiphomeListModel{ _youpaiphomeListModel = youpaiphomeListModel; CGFloat width = 0; if ([NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores].length>5) { width = [LCTools widthWithString:[NSString stringWithFormat:@"%@",@"12345"] withFont:[UIFont systemFontOfSize:12]]; }else{ width = [LCTools widthWithString:[NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores] withFont:[UIFont systemFontOfSize:12]]; } [self.youpaiprightBottomBtn mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.offset(0.0f); make.centerY.mas_equalTo(0); make.size.mas_offset(CGSizeMake(width+5+4.5+20, 20.0f)); }]; [self.youpaippeopleLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-5); make.centerY.mas_equalTo(0); make.width.mas_equalTo(width+5); }]; [self youpaifeditBtnCountWithCount:youpaiphomeListModel.youpaipimg.count > 3 ? 3 : youpaiphomeListModel.youpaipimg.count]; [self.youpaipmemberAvatarBgV updateConstraints:^(MASConstraintMaker *make) { make.width.offset(self.youpaipmemberAvatars.count * 24.0f - (self.youpaipmemberAvatars.count - 1.0f) * 4.0f); }]; for (NSInteger i = 0; i < self.youpaipmemberAvatars.count; i ++) { UIImageView *imgV = self.youpaipmemberAvatars[i]; imgV.layer.cornerRadius = 12.0f; imgV.clipsToBounds = YES; imgV.layer.borderWidth = 0.5; imgV.layer.borderColor = HexColorFromRGBA(0xffffff, 0.5).CGColor; imgV.frame = CGRectMake(i * 24.0f - i * 4.0f, 0.0f, 24.0f, 24.0f); Image *url = youpaiphomeListModel.youpaipimg[i]; [imgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:url.youpaipimg] placeholderImage:nil];; } [self.youpaipimageV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:youpaiphomeListModel.youpaipcover_img] urlWithImageScale:60] placeholderImage:nil]; self.youpaiptitleLabel.text = youpaiphomeListModel.youpaiptitle; if ([youpaiphomeListModel.youpaippwd isEqualToString:@"1"]) {//0未上锁;1已上锁 self.youpaiphomeLockBtn.hidden = NO; }else{ self.youpaiphomeLockBtn.hidden = YES; } self.youpaippeopleLabel.text = [NSString stringWithFormat:@"%ld",youpaiphomeListModel.youpaipscores]; [self.youpaipmyHomeBtn setTitle:youpaiphomeListModel.youpaiprooms_title forState:UIControlStateNormal]; } /// 顶部榜单相关函数 - (void)youpaifeditBtnCountWithCount:(NSInteger)count{ if (count >= self.youpaipmemberAvatars.count) { [self youpaifaddBtnWithCount:count - self.youpaipmemberAvatars.count]; }else{ [self youpaifdeleteBtnWithCount:self.youpaipmemberAvatars.count - count]; } } - (void)youpaifdeleteBtnWithCount:(NSInteger)count{ if (count != 0) { for (NSInteger i = 0; i < count; i ++) { UIImageView *btn = self.youpaipmemberAvatars.lastObject; [self.youpaipmemberAvatars removeLastObject]; [btn removeFromSuperview]; } } } - (void)youpaifaddBtnWithCount:(NSInteger)count{ for (NSInteger i = 0; i < count; i ++) { [self youpaifcreateBtn]; } } - (void)youpaifcreateBtn{ UIImageView *imgV = [[UIImageView alloc] init]; imgV.contentMode = UIViewContentModeScaleAspectFill; [self.youpaipmemberAvatarBgV addSubview:imgV]; [self.youpaipmemberAvatars addObject:imgV]; } - (NSMutableArray *)youpaipmemberAvatars{ if (_youpaipmemberAvatars == nil) { _youpaipmemberAvatars = [NSMutableArray array]; } return _youpaipmemberAvatars; } @end