Files
featherVoice/QXLive/Tabbar/弹窗/QXNiceGiftPopView.m

214 lines
9.4 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXNiceGiftPopView.m
// QXLive
//
// Created by on 2025/5/13.
//
#import "QXNiceGiftPopView.h"
#import "GKPageControl.h"
#import "QXGiftCell.h"
2025-10-20 09:43:10 +08:00
#import "QXHomePageNetwork.h"
2025-08-08 10:49:36 +08:00
@interface QXNiceGiftPopView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIImageView *lightBgImageView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIImageView *timeDownbgView;
@property (nonatomic,strong)UILabel *timeDownLabel;
@property (nonatomic,strong)UIView *giftBgView;
2025-10-20 09:43:10 +08:00
//@property (nonatomic,strong)UIButton *ruleBtn;
2025-08-08 10:49:36 +08:00
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)GKPageControl *pageControl;
@property (nonatomic,strong)UILabel *messageLabel;
@property (nonatomic,strong)UIButton *getBtn;
@property (nonatomic,strong)UIButton *closeBtn;
2025-10-20 09:43:10 +08:00
@property (nonatomic,strong)QXNiceGiftRechargeModel *model;
2025-08-08 10:49:36 +08:00
@end
@implementation QXNiceGiftPopView
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(582));
[self initSubViews];
}
return self;
}
-(void)initSubViews{
self.lightBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a_pop_bg"]];
[self addSubview:self.lightBgImageView];
[self.lightBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.equalTo(self);
}];
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a_pop_nice_gift"]];
2025-10-30 00:45:15 +08:00
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
2025-08-08 10:49:36 +08:00
[self addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.centerY.equalTo(self);
make.size.mas_equalTo(CGSizeMake(ScaleWidth(275), ScaleWidth(338)));
}];
self.timeDownbgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gift_time_bg"]];
[self addSubview:self.timeDownbgView];
[self.timeDownbgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgImageView).offset(ScaleWidth(117));
make.left.equalTo(self.bgImageView).offset(9);
2025-10-20 09:43:10 +08:00
make.right.equalTo(self.bgImageView).offset(-9);
make.width.mas_equalTo(ScaleWidth(20));
2025-08-08 10:49:36 +08:00
}];
self.timeDownLabel = [[UILabel alloc] init];
self.timeDownLabel.textColor = RGB16(0x666666);
2025-10-20 09:43:10 +08:00
self.timeDownLabel.text = QXText(@"截止时间");
2025-08-08 10:49:36 +08:00
self.timeDownLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:self.timeDownLabel];
[self.timeDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.timeDownbgView);
make.left.equalTo(self.timeDownbgView).offset(19);
make.right.equalTo(self.timeDownbgView).offset(-19);
}];
2025-10-20 09:43:10 +08:00
// self.ruleBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 54, 20)];
// self.ruleBtn.backgroundColor = QXConfig.themeColor;
// [self.ruleBtn addTarget:self action:@selector(ruleAction) forControlEvents:(UIControlEventTouchUpInside)];
// [self.ruleBtn setTitle:QXText(@"规则") forState:(UIControlStateNormal)];
// self.ruleBtn.titleLabel.font = [UIFont systemFontOfSize:12];
// [self.ruleBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
// [self.ruleBtn addRoundedCornersWithRadius:10 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)];
// [self addSubview:self.ruleBtn];
// [self.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.right.equalTo(self.bgImageView);
// make.centerY.equalTo(self.timeDownbgView);
// make.size.mas_equalTo(CGSizeMake(ScaleWidth(54), ScaleWidth(20)));
// }];
2025-08-08 10:49:36 +08:00
self.giftBgView = [[UIView alloc] init];
// self.giftBgView.backgroundColor = [UIColor whiteColor];
[self.giftBgView addRoundedCornersWithRadius:13];
[self addSubview:self.giftBgView];
[self.giftBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.timeDownbgView.mas_bottom).offset(ScaleWidth(3));
make.left.equalTo(self.bgImageView).offset(15);
make.right.equalTo(self.bgImageView).offset(-15);
make.bottom.equalTo(self.bgImageView).offset(-ScaleWidth(51));
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((ScaleWidth(275-15*2-12*2-3*8))/4, ScaleWidth(76));
layout.minimumLineSpacing = 8;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.pagingEnabled = YES;
[self.giftBgView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(12);
make.top.mas_equalTo(ScaleWidth(16));
make.height.mas_equalTo(ScaleWidth(76));
make.right.mas_equalTo(-12);
}];
_pageControl = [[GKPageControl alloc] init];
_pageControl.style = GKPageControlStyleRectangle;
_pageControl.dotWidth = 15;
_pageControl.dotHeight = 5;
_pageControl.dotMargin = 2;
_pageControl.pageIndicatorTintColor = RGB16(0xEBEBEB);
_pageControl.currentPageIndicatorTintColor = QXConfig.textColor;
[self.giftBgView addSubview:self.pageControl];
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.collectionView.mas_bottom).offset(9);
make.height.mas_equalTo(5);
make.right.mas_equalTo(-48);
make.left.mas_equalTo(48);
}];
self.messageLabel = [[UILabel alloc] init];
self.messageLabel.font = [UIFont systemFontOfSize:12];
self.messageLabel.numberOfLines = 0;
2025-10-20 09:43:10 +08:00
self.messageLabel.text = @"";
2025-08-08 10:49:36 +08:00
self.messageLabel.textColor = QXConfig.textColor;
[self.giftBgView addSubview:self.messageLabel];
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(12);
make.right.mas_equalTo(-12);
make.top.equalTo(self.pageControl.mas_bottom).offset(2);
make.bottom.equalTo(self.giftBgView).offset(-5);
}];
self.getBtn = [[UIButton alloc] init];
[self.getBtn addRoundedCornersWithRadius:21];
self.getBtn.backgroundColor = QXConfig.themeColor;
2025-10-20 09:43:10 +08:00
[self.getBtn setTitle:QXText(@"立即充值") forState:(UIControlStateNormal)];
2025-08-08 10:49:36 +08:00
[self.getBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
self.getBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.getBtn addTarget:self action:@selector(getAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.getBtn];
[self.getBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgImageView).offset(-ScaleWidth(16));
make.height.mas_equalTo(42);
make.right.equalTo(self.bgImageView).offset(-48);
make.left.equalTo(self.bgImageView).offset(48);
}];
self.closeBtn = [[UIButton alloc] init];
[self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)];
[self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.closeBtn];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self.bgImageView.mas_bottom).offset(8);
make.height.width.mas_equalTo(30);
}];
2025-10-20 09:43:10 +08:00
[self getGiftList];
2025-08-08 10:49:36 +08:00
}
2025-10-20 09:43:10 +08:00
-(void)getGiftList{
MJWeakSelf
[QXHomePageNetwork getSkyDropGiftListSuccessBlock:^(QXNiceGiftRechargeModel * _Nonnull model) {
weakSelf.model = model;
weakSelf.timeDownLabel.text = [NSString stringWithFormat:@"结束时间:%@",model.effective_time];
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:model.counter];
[attr yy_setColor:QXConfig.themeColor range:[model.counter rangeOfString:model.money]];
[attr yy_setColor:QXConfig.themeColor range:[model.counter rangeOfString:model.diamond]];
weakSelf.messageLabel.attributedText = attr;
[weakSelf.collectionView reloadData];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
if (weakSelf.refreshBlcock) {
weakSelf.refreshBlcock();
2025-08-08 10:49:36 +08:00
}
2025-10-20 09:43:10 +08:00
}];
2025-08-08 10:49:36 +08:00
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
2025-10-20 09:43:10 +08:00
return self.model.gift_list.count;
2025-08-08 10:49:36 +08:00
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath];
cell.cellType = QXGiftCellTypeNiceGift;
2025-10-20 09:43:10 +08:00
cell.niceGiftModel = self.model.gift_list[indexPath.row];
2025-08-08 10:49:36 +08:00
return cell;
}
2025-10-20 09:43:10 +08:00
2025-08-08 10:49:36 +08:00
//
-(void)getAction{
2025-10-20 09:43:10 +08:00
if (self.rechargeActionBlock) {
self.rechargeActionBlock(self.model.money,self.model.gift_bag_id);
2025-08-08 10:49:36 +08:00
}
}
-(void)closeAction{
if (self.closeActionBlock) {
self.closeActionBlock();
}
}
@end