// // QXMainHeaderView.m // QXLive // // Created by 启星 on 2025/5/9. // #import "QXMainHeaderView.h" #import "QXSeatHeaderView.h" #import "CKShimmerLabel.h" #import "QXMineHomeToolsCell.h" #import "QXServiceModel.h" #import "QXBanner.h" #import #import "QXUserHomePageViewController.h" @interface QXMainHeaderView() @property (nonatomic, strong) QXSeatHeaderView *userHeaderView; @property (nonatomic, strong) UIImageView *sexImageView; //@property (nonatomic, strong) UILabel *nameLabel; @property (nonatomic, strong) CKShimmerLabel *nameLabel; @property (nonatomic, strong) UILabel *idLabel; @property (nonatomic, strong) UIButton *idCopyBtn; // 贵族 @property (nonatomic, strong) UIView *nobilityBgView; @property (nonatomic, strong) UIImageView *nobilityImageView; @property (nonatomic, strong) UIView *userHomeView; @property (nonatomic, strong) UILabel *userNobilityTitleLabel; @property (nonatomic, strong) UIImageView *userNobilityImageView; @property (nonatomic, strong) UIButton *userHomeBtn; @property (nonatomic, strong) UIImageView *useCodeImageView; /// 顶部工具栏 @property (nonatomic, strong) UIView *topBgView; @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) UIButton *roomBtn; /// 标签是否已经创建过了 @property (nonatomic, strong) NSMutableArray *iconArray; /// 工具栏 @property (nonatomic, strong) NSMutableArray *toolsArray; @property (nonatomic, strong)QXServiceModel *rechargeModel; @property (nonatomic, strong)SDCycleScrollView *cycleScrollView; @property (nonatomic, strong)UIView *walletBgView; @property (nonatomic, strong)UILabel *walletTitleLabel; @property (nonatomic, strong)UIImageView *walletBgImageView; @property (nonatomic, strong)UILabel *walletBottomLabel; @property (nonatomic, strong)UILabel *walletMoneyLabel; @property (nonatomic, strong)UIButton *walletBtn; @property (nonatomic, strong)UIImageView *giftWallBgImageView; @property (nonatomic, strong)UILabel *giftWallTitleLabel; @property (nonatomic, strong)UIButton *giftWallBtn; @property (nonatomic, strong)NSMutableArray *bannerImages; @end @implementation QXMainHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ MJWeakSelf self.userHeaderView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake(16, 18, 76, 91)]; [self.userHeaderView addTapBlock:^(id _Nonnull obj) { if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didClickOptionType:)]) { [weakSelf.delegate didClickOptionType:QXMainHeaderOptionTypeGotoHome]; } }]; [self addSubview:self.userHeaderView]; // self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.userHeaderView.top, self.width-self.userHeaderView.right-16-6, 23)]; self.nameLabel = [[CKShimmerLabel alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.userHeaderView.top+5, self.width-self.userHeaderView.right-16-6, 22)]; self.nameLabel.shimmerWidth = 20; self.nameLabel.shimmerRadius = 20; self.nameLabel.durationTime = 1; self.nameLabel.text = @"羽声语音"; // self.nameLabel.shimmerColor = [UIColor yellowColor]; self.nameLabel.repeat = YES; self.nameLabel.textColor = RGB16A(0xffffff,0.85); self.nameLabel.font = [UIFont boldSystemFontOfSize:18]; // [self.nameLabel startShimmer]; [self addSubview:self.nameLabel]; self.sexImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.nameLabel.bottom+4, 17, 17)]; [self addSubview:self.sexImageView]; // [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.bottom.equalTo(self.userHeaderView); // make.height.width.mas_equalTo(16); // }]; self.idLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.sexImageView.right+6, self.nameLabel.bottom+6, 80, 17)]; self.idLabel.textColor = RGB16(0x666666); self.idLabel.font = [UIFont systemFontOfSize:12]; self.idLabel.text = @"ID:"; [self addSubview:self.idLabel]; self.useCodeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_usercode_isLiang"]]; self.useCodeImageView.frame = CGRectMake(0, 0, 32, 13); self.useCodeImageView.hidden = YES; [self addSubview:self.useCodeImageView]; self.idCopyBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.idLabel.right, 0, 25, 25)]; self.idCopyBtn.centerY = self.idLabel.centerY; [self.idCopyBtn setImage:[UIImage imageNamed:@"id_copy"] forState:(UIControlStateNormal)]; [self.idCopyBtn addTarget:self action:@selector(idCopyClick) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.idCopyBtn]; self.userHomeView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60-16, 0, 54, 23)]; self.userHomeView.layer.cornerRadius = self.userHomeView.height/2.0; self.userHomeView.layer.shadowColor = [UIColor grayColor].CGColor; self.userHomeView.layer.shadowOpacity = 0.3; self.userHomeView.layer.shadowOffset = CGSizeMake(0, 2); self.userHomeView.layer.shadowRadius = 2; self.userHomeView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.userHomeView.bounds cornerRadius:self.userHomeView.layer.cornerRadius].CGPath; self.userHomeView.layer.masksToBounds = NO; self.userHomeView.centerY = self.userHeaderView.centerY; self.userHomeView.backgroundColor = [UIColor whiteColor]; [self addSubview:self.userHomeView]; self.userHomeBtn = [[UIButton alloc] initWithFrame:self.userHomeView.bounds]; [self.userHomeBtn setBackgroundImage:[UIImage imageNamed:@"mine_edit_btn"] forState:(UIControlStateNormal)]; [self.userHomeBtn addTarget:self action:@selector(gotoUserHomePageClick) forControlEvents:(UIControlEventTouchUpInside)]; [self.userHomeView addSubview:self.userHomeBtn]; // NSArray* nameArr = @[ // QXText(@"关注"), QXText(@"粉丝"), QXText(@"好友"), QXText(@"访客") // ]; NSArray* nameArr = @[ QXText(@"关注"), QXText(@"粉丝"),QXText(@"访客") ]; CGFloat width = (SCREEN_WIDTH-60)/3; for (int i = 0; i < nameArr.count; i ++) { UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(30+width*i, self.userHeaderView.bottom+10, width, 25)]; countLabel.textAlignment = NSTextAlignmentCenter; countLabel.textColor = RGB16(0xCCCDC8); countLabel.tag = 10 + i; countLabel.font = [UIFont fontWithName:@"DIN Condensed" size:22]; countLabel.text = @"0"; [self addSubview:countLabel]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(countLabel.left, countLabel.bottom+5, width, 18)]; titleLabel.textColor = RGB16(0XCCCDC8); titleLabel.font = [UIFont systemFontOfSize:12]; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.text = nameArr[i]; [self addSubview:titleLabel]; UIControl *c = [[UIControl alloc] initWithFrame:CGRectMake(countLabel.left, countLabel.top, width, countLabel.height+titleLabel.height+5)]; c.tag = 20 + i; [c addTarget:self action:@selector(viewClick:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:c]; } self.nobilityBgView = [[UIView alloc] initWithFrame:CGRectMake(30, self.userHeaderView.bottom+80, SCREEN_WIDTH-60, ScaleWidth(40))]; [self.nobilityBgView addTapBlock:^(id _Nonnull obj) { if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didClickOptionType:)]) { [weakSelf.delegate didClickOptionType:QXMainHeaderOptionTypeNobility]; } }]; [self addSubview:self.nobilityBgView]; self.nobilityImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_nobility_bg"]]; self.nobilityImageView.frame = self.nobilityBgView.bounds; self.nobilityImageView.contentMode = UIViewContentModeScaleToFill; [self.nobilityBgView addSubview:self.nobilityImageView]; self.userNobilityImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"arrowRight"] imageByTintColor:RGB16(0xEECE72)]]; self.userNobilityImageView.frame = CGRectMake(self.nobilityImageView.width-10-16, (self.nobilityBgView.height-16)/2.0, 16, 16); [self.nobilityBgView addSubview:self.userNobilityImageView]; self.userNobilityTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userNobilityImageView.left-32, (self.nobilityBgView.height-20)/2, 32, 20)]; self.userNobilityTitleLabel.text = QXText(@"更多"); self.userNobilityTitleLabel.font = [UIFont systemFontOfSize:14]; self.userNobilityTitleLabel.textColor = [UIColor colorWithHexString:@"#EECE72"]; [self.nobilityBgView addSubview:self.userNobilityTitleLabel]; self.topBgView = [[UIView alloc] initWithFrame:CGRectMake(16, self.nobilityBgView.bottom, SCREEN_WIDTH-32, 90)]; [self.topBgView addRoundedCornersWithRadius:8]; self.topBgView.backgroundColor = RGB16A(0xffffff, 0.06); [self addSubview:self.topBgView]; NSInteger maxCount = 5; CGFloat btnWith = (int)(SCREEN_WIDTH-32-1)/maxCount; CGFloat btnHeight = self.topBgView.height; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(btnWith, btnHeight); layout.minimumLineSpacing = 0; layout.minimumInteritemSpacing = 0; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXMineHomeToolsCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXMineHomeToolsCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.backgroundColor = UIColor.clearColor; [self.topBgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.right.equalTo(self.topBgView); }]; self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(self.topBgView.left, self.topBgView.bottom+12, self.topBgView.width, 64) delegate:self placeholderImage:nil]; self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; [self.cycleScrollView addRoundedCornersWithRadius:8]; [self addSubview:self.cycleScrollView]; self.walletBgView = [[UIView alloc] initWithFrame:CGRectMake(self.topBgView.left, self.cycleScrollView.bottom+12, self.topBgView.width, 108)]; self.walletBgView.backgroundColor = RGB16(0x231F2C); [self.walletBgView addRoundedCornersWithRadius:8]; [self addSubview:self.walletBgView]; self.walletTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, 200, 16)]; self.walletTitleLabel.text = @"我的钱包"; self.walletTitleLabel.font = [UIFont systemFontOfSize:14]; self.walletTitleLabel.textColor = RGB16(0x929196); [self.walletBgView addSubview:self.walletTitleLabel]; CGFloat walletWidth = (self.topBgView.width - 16*3) / 2; self.walletBgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.topBgView.left, self.walletTitleLabel.bottom+8, walletWidth, 60)]; self.walletBgImageView.backgroundColor = RGB16(0xFFE38E); [self.walletBgImageView addRoundedCornersWithRadius:8]; [self.walletBgView addSubview:self.walletBgImageView]; self.walletBottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.walletBgImageView.left, self.walletBgImageView.bottom-14-11, walletWidth, 14)]; self.walletBottomLabel.text = @"钱包"; self.walletBottomLabel.textAlignment = NSTextAlignmentCenter; self.walletBottomLabel.font = [UIFont systemFontOfSize:12]; self.walletBottomLabel.textColor = RGB16(0x333333); [self.walletBgView addSubview:self.walletBottomLabel]; self.walletMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.walletBgImageView.left, self.walletBgImageView.top+11, walletWidth, 25)]; self.walletMoneyLabel.text = @"0"; self.walletMoneyLabel.textAlignment = NSTextAlignmentCenter; self.walletMoneyLabel.font = [UIFont fontWithName:@"DIN Condensed" size:25]; self.walletMoneyLabel.textColor = RGB16(0x222222); [self.walletBgView addSubview:self.walletMoneyLabel]; self.giftWallBgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.walletBgImageView.right+16, self.walletBgImageView.top, walletWidth, self.walletBgImageView.height)]; self.giftWallBgImageView.backgroundColor = RGB16(0xF1B3FF); [self.giftWallBgImageView addRoundedCornersWithRadius:8]; [self.walletBgView addSubview:self.giftWallBgImageView]; self.giftWallTitleLabel = [[UILabel alloc] initWithFrame:self.giftWallBgImageView.frame]; self.giftWallTitleLabel.text = @"礼物墙"; self.giftWallTitleLabel.textAlignment = NSTextAlignmentCenter; self.giftWallTitleLabel.font = [UIFont fontWithName:@"DIN Condensed" size:20]; self.giftWallTitleLabel.textColor = RGB16(0x222222); [self.walletBgView addSubview:self.giftWallTitleLabel]; self.walletBtn = [[UIButton alloc] initWithFrame:self.walletBgImageView.frame]; [self.walletBtn addTarget:self action:@selector(walletAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.walletBgView addSubview:self.walletBtn]; self.giftWallBtn = [[UIButton alloc] initWithFrame:self.giftWallBgImageView.frame]; [self.giftWallBtn addTarget:self action:@selector(giftWalltAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.walletBgView addSubview:self.giftWallBtn]; } -(CGFloat)getHeight{ return self.walletBgView.bottom+6; } -(void)setCoin:(NSString *)coin{ _coin = coin; self.walletMoneyLabel.text = [NSString stringWithFormat:@"%.2f",coin.doubleValue]; } -(void)setBannerArray:(NSArray *)bannerArray{ _bannerArray = bannerArray; [self.bannerImages removeAllObjects]; for (QXBanner *banner in bannerArray) { [self.bannerImages addObject:banner.image]; } self.cycleScrollView.imageURLStringsGroup = self.bannerImages; } -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{ if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } QXBanner *banner = self.bannerArray[index]; if ([banner.type isEqualToString:@"2"]) { QXBaseWebViewController *webVc = [[QXBaseWebViewController alloc] init]; webVc.urlStr = banner.url; [self.navigationController pushViewController:webVc animated:YES]; }else if ([banner.type isEqualToString:@"3"]){ [[QXGlobal shareGlobal] joinRoomWithRoomId:banner.aid isRejoin:NO navagationController:self.navigationController]; }else if ([banner.type isEqualToString:@"4"]){ QXUserHomePageViewController *userHomePage = [[QXUserHomePageViewController alloc] init]; userHomePage.user_id = banner.aid; [self.viewController.navigationController pushViewController:userHomePage animated:YES]; } } -(void)reloadData{ if ([self.toolsArray containsObject:self.rechargeModel]) { return; } if (QXGlobal.shareGlobal.isOpenRecharge) { [self.toolsArray insertObject:self.rechargeModel atIndex:0]; } [self.collectionView reloadData]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.toolsArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXMineHomeToolsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMineHomeToolsCell" forIndexPath:indexPath]; cell.model = self.toolsArray[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) { QXServiceModel *model = self.toolsArray[indexPath.row]; [self.delegate didClickOptionType:model.type]; } } -(void)viewClick:(UIControl*)sender{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) { [self.delegate didClickOptionType:sender.tag]; } } -(void)walletAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) { [self.delegate didClickOptionType:QXMainHeaderOptionTypeWallet]; } } -(void)giftWalltAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) { [self.delegate didClickOptionType:QXMainHeaderOptionTypeGiftWall]; } } -(void)gotoUserHomePageClick{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) { [self.delegate didClickOptionType:QXMainHeaderOptionTypeGotoEdit]; } } -(void)setUserModel:(QXUserModel *)userModel{ _userModel = userModel; [self.userHeaderView setHeadIcon:userModel.avatar dress:userModel.dress]; [self.userHeaderView.nobilityImageView sd_setImageWithURL:[NSURL URLWithString:userModel.nobility_image]]; if ([userModel.nickname_color isExist]) { self.nameLabel.shimmerColor = [UIColor colorWithHexString:userModel.nickname_color]; [self.nameLabel startShimmer]; }else{ [self.nameLabel stopShimmer]; } self.nameLabel.text = userModel.nickname; self.idLabel.text = [NSString stringWithFormat:@"ID:%@",userModel.user_code]; UILabel *followLabel = [self viewWithTag:10]; UILabel *fansLabel = [self viewWithTag:11]; UILabel *lookLabel = [self viewWithTag:12]; followLabel.text = userModel.follow_num; fansLabel.text = userModel.fans_num; lookLabel.text = userModel.look_me_num; for (UIView*v in self.iconArray) { [v removeFromSuperview]; } for (int i = 0;i