275 lines
12 KiB
Objective-C
275 lines
12 KiB
Objective-C
//
|
|
// XPMineChooseGiveGiftView.m
|
|
// YuMi
|
|
//
|
|
// Created by YuMi on 2022/11/2.
|
|
//
|
|
//#import "XPPageControl.h"
|
|
#import "XPMineChooseGiveGiftView.h"
|
|
#import "XPMineChooseGiveGiftViewCell.h"
|
|
#import "XPGuildEmptyCollectionViewCell.h"
|
|
#import "UIView+Corner.h"
|
|
@interface XPMineChooseGiveGiftView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
@property (nonatomic,strong) UIView *bgView;
|
|
//@property (nonatomic,strong) XPPageControl *pageControl;
|
|
@property(nonatomic, strong) UIPageControl *pageControl;
|
|
@property (nonatomic,strong) NSMutableArray *listData;
|
|
@property (nonatomic,strong) NSIndexPath *indexPath;
|
|
|
|
@property (nonatomic,strong) UILabel *numTitleLabel;
|
|
|
|
@property (nonatomic,strong) UIButton *allBtn;
|
|
@end
|
|
@implementation XPMineChooseGiveGiftView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.bgView];
|
|
[self addSubview:self.collectionView];
|
|
[self addSubview:self.pageControl];
|
|
[self addSubview:self.numTitleLabel];
|
|
[self addSubview:self.textField];
|
|
[self addSubview:self.allBtn];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(15);
|
|
make.trailing.mas_equalTo(-15);
|
|
make.top.equalTo(self);
|
|
make.height.mas_equalTo(kGetScaleWidth(268));
|
|
}];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(15);
|
|
make.trailing.mas_equalTo(-15);
|
|
make.top.equalTo(self);
|
|
make.height.mas_equalTo(kGetScaleWidth(248));
|
|
}];
|
|
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self);
|
|
make.bottom.mas_equalTo(self.bgView).offset(-4);
|
|
make.height.mas_equalTo(8);
|
|
make.width.mas_equalTo(KScreenWidth);
|
|
}];
|
|
|
|
UIView *bgView = [[UIView alloc] init];
|
|
[bgView setCornerRadius:12];
|
|
bgView.backgroundColor = UIColorFromRGB(0xf7f7f7);
|
|
[self insertSubview:bgView belowSubview:self.numTitleLabel];
|
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.bgView.mas_bottom).offset(14);
|
|
make.leading.trailing.mas_equalTo(self).inset(15);
|
|
make.height.mas_equalTo(52);
|
|
}];
|
|
|
|
[self.numTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.equalTo(bgView);
|
|
make.leading.mas_equalTo(bgView).offset(10);
|
|
}];
|
|
|
|
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.numTitleLabel.mas_trailing).offset(8);
|
|
make.height.mas_equalTo(28);
|
|
make.width.mas_equalTo(kGetScaleWidth(156));
|
|
make.centerY.mas_equalTo(bgView);
|
|
}];
|
|
|
|
[self.allBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_greaterThanOrEqualTo(38);
|
|
make.height.mas_equalTo(24);
|
|
make.centerY.mas_equalTo(bgView);
|
|
make.trailing.mas_equalTo(bgView).offset(-10);
|
|
}];
|
|
}
|
|
-(void)setListData:(NSMutableArray *)listData count:(NSInteger)count{
|
|
self.listData = listData;
|
|
if(listData.count == 0)return;
|
|
[self.collectionView reloadData];
|
|
|
|
self.pageControl.numberOfPages = count;
|
|
self.pageControl.currentPage = 0;
|
|
self.pageControl.hidden = count == 1;
|
|
self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:1.0 green:0.55 blue:0.01 alpha:1.0]; // 当前点颜色 #FF8C03
|
|
self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0.81 green:0.81 blue:0.81 alpha:1.0]; // 其他点颜色 #CECECE
|
|
|
|
}
|
|
-(void)resignFirstResponder{
|
|
[self.textField resignFirstResponder];
|
|
}
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if(self.listData.count == 0){
|
|
XPGuildEmptyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class]) forIndexPath:indexPath];
|
|
[cell setConstraints];
|
|
[cell setTitle:YMLocalizedString(@"XPMineChooseGiveGiftView5")];
|
|
return cell;
|
|
}
|
|
NSInteger count = indexPath.section / 4;
|
|
NSInteger index = indexPath.row == 0 ? indexPath.section + count * 4 : indexPath.section + count * 4 + 4;
|
|
GiftInfoModel *giftModel = self.listData[index];
|
|
if(giftModel.isEmpty == YES){
|
|
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
|
|
cell.backgroundColor = [UIColor clearColor];
|
|
return cell;
|
|
}
|
|
XPMineChooseGiveGiftViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPMineChooseGiveGiftViewCell class]) forIndexPath:indexPath];
|
|
cell.giftModel = giftModel;
|
|
cell.isChoose = NO;
|
|
if(self.indexPath != nil){
|
|
if(self.indexPath.section == indexPath.section){
|
|
cell.isChoose = self.indexPath.row == indexPath.row;
|
|
}
|
|
}
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
if(self.listData.count == 0)return 1;
|
|
return 2;
|
|
|
|
|
|
}
|
|
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
|
|
// NSInteger page = scrollView.contentOffset.x / (KScreenWidth - 30);
|
|
NSInteger currentPage = round(scrollView.contentOffset.x / scrollView.frame.size.width);
|
|
self.pageControl.currentPage = currentPage;
|
|
}
|
|
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
|
|
|
return self.listData.count > 0 ? self.listData.count / 2 : 1;
|
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if(self.listData.count == 0)return self.collectionView.frame.size;
|
|
return CGSizeMake(kGetScaleWidth(72), kGetScaleWidth(107));
|
|
}
|
|
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
|
|
if(self.listData.count == 0)return UIEdgeInsetsMake(0,0, 0, 0);
|
|
if(section == 0){
|
|
return UIEdgeInsetsMake(kGetScaleWidth(17), kGetScaleWidth(14), 0, 0);
|
|
}else if (section == self.listData.count / 2 - 1){
|
|
return UIEdgeInsetsMake(kGetScaleWidth(17), kGetScaleWidth(10), 0, kGetScaleWidth(14));
|
|
}else if (section % 4 == 0){
|
|
return UIEdgeInsetsMake(kGetScaleWidth(17), kGetScaleWidth(28), 0, 0);
|
|
}
|
|
return UIEdgeInsetsMake(kGetScaleWidth(17), kGetScaleWidth(10), 0, 0);
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
id cell = [collectionView cellForItemAtIndexPath:indexPath];
|
|
if([cell isKindOfClass:[XPMineChooseGiveGiftViewCell class]]){
|
|
XPMineChooseGiveGiftViewCell *getCell = (XPMineChooseGiveGiftViewCell *)cell;
|
|
self.indexPath = indexPath;
|
|
self.chooseGiftModel = getCell.giftModel;
|
|
[self.collectionView reloadData];
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(textFieldDidChangeWithText:)]){
|
|
[self.delegate textFieldDidChangeWithText:self.textField.text];
|
|
}
|
|
|
|
self.textField.text = @"1";
|
|
}
|
|
}
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
|
|
return kGetScaleWidth(10);
|
|
}
|
|
#pragma mark- UITextFieldDelegate
|
|
-(void)textFieldDidChange:(UITextField *)textField{
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(textFieldDidChangeWithText:)]){
|
|
[self.delegate textFieldDidChangeWithText:textField.text];
|
|
}
|
|
}
|
|
-(void)allChooseAction{
|
|
if(self.chooseGiftModel == nil){
|
|
[XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPMineChooseGiveGiftView2")];
|
|
return;
|
|
}
|
|
self.textField.text = @(self.chooseGiftModel.count).stringValue;
|
|
}
|
|
#pragma mark -懒加载
|
|
|
|
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView){
|
|
MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc]init];
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
_collectionView.pagingEnabled = YES;
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
[_collectionView registerClass:[XPMineChooseGiveGiftViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPMineChooseGiveGiftViewCell class])];
|
|
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];
|
|
[_collectionView registerClass:[XPGuildEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGuildEmptyCollectionViewCell class])];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
-(UIView *)bgView{
|
|
if (!_bgView){
|
|
_bgView = [UIView new];
|
|
_bgView.backgroundColor = UIColorFromRGB(0xF7F7F7);
|
|
[_bgView setCornerRadius:12];
|
|
}
|
|
return _bgView;
|
|
}
|
|
- (UIPageControl *)pageControl{
|
|
if (!_pageControl){
|
|
_pageControl = [[UIPageControl alloc]init];
|
|
}
|
|
return _pageControl;
|
|
}
|
|
|
|
- (UILabel *)numTitleLabel {
|
|
if (!_numTitleLabel) {
|
|
_numTitleLabel = [[UILabel alloc] init];
|
|
_numTitleLabel.font = [UIFont systemFontOfSize:11];
|
|
_numTitleLabel.textColor = UIColorFromRGB(0x7b7b7d);
|
|
_numTitleLabel.text = YMLocalizedString(@"XPMineChooseGiveGiftView0");
|
|
}
|
|
return _numTitleLabel;
|
|
}
|
|
|
|
-(MSBaseTextField *)textField{
|
|
if (!_textField){
|
|
_textField = [MSBaseTextField new];
|
|
_textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_textField.font = [UIFont systemFontOfSize:kGetScaleWidth(20) weight:UIFontWeightMedium];
|
|
_textField.textColor = [DJDKMIMOMColor inputTextColor];
|
|
_textField.attributedPlaceholder = [[NSMutableAttributedString alloc]initWithString:@"0" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kGetScaleWidth(20) weight:UIFontWeightRegular],NSForegroundColorAttributeName:[DJDKMIMOMColor disableButtonTextColor]}];
|
|
_textField.text = @"1";
|
|
[_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
|
|
}
|
|
return _textField;
|
|
}
|
|
|
|
-(UIButton *)allBtn{
|
|
if (!_allBtn){
|
|
_allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_allBtn setTitle:YMLocalizedString(@"XPMineChooseGiveGiftView1") forState:UIControlStateNormal];
|
|
_allBtn.titleLabel.font = kFontMedium(12);
|
|
[_allBtn setTitleColor:UIColorFromRGB(0xFF8C03) forState:UIControlStateNormal];
|
|
_allBtn.backgroundColor = [UIColor whiteColor];
|
|
[_allBtn setCornerRadius:12
|
|
corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner
|
|
borderWidth:1
|
|
borderColor:UIColorFromRGB(0xFF8C03)];
|
|
[_allBtn addTarget:self action:@selector(allChooseAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _allBtn;
|
|
}
|
|
-(NSString *)giftCount{
|
|
return self.textField.text;
|
|
}
|
|
|
|
@end
|