Files
yinmeng-ios/xplan-ios/Main/ModuleKit/SendGiftView/View/XPGiftInfoView.m
2022-10-21 19:13:04 +08:00

709 lines
27 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// XPGiftMiddleView.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/9.
//
#import "XPGiftInfoView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
#import "XPHtmlUrl.h"
#import "ThemeColor+SendGift.h"
///Model
#import "GiftInfoModel.h"
#import "GiftReceiveInfoModel.h"
#import "RoomInfoModel.h"
///View
#import "XPGiftItemCollectionViewCell.h"
#import "XPGiftEmptyCollectionViewCell.h"
#import "XPGiftWeekStarCollectionViewCell.h"
#import "XPGiftCollectionViewFlowLayout.h"
@interface XPGiftInfoView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, XPGiftWeekStarCollectionViewCellDelegate>
///滚动的容器
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UIStackView *segmentStackView;
///普通礼物
@property (nonatomic,strong) UIButton *normalGiftButton;
///背包礼物
@property (nonatomic,strong) UIButton *packGiftButton;
///幸运礼物
@property (nonatomic,strong) UIButton *luckyGiftButton;
///贵族礼物
@property (nonatomic,strong) UIButton *nobleGiftButton;
///周星礼物
@property (nonatomic, strong) UIButton *weekStarButton;
///涂鸦礼物
@property (nonatomic,strong) UIButton *graffitiButton;
///个播礼物
@property (nonatomic,strong) UIButton *anchorButton;
///背包总价值
@property (nonatomic,strong) UILabel *totalValueLabel;
///
@property (nonatomic,strong) UIStackView *giftStackView;
///l礼物列表
@property (nonatomic,strong) UICollectionView *giftcollectionView;
///分页控件
@property (nonatomic, strong) UIPageControl *pageController;
///展示的数据源
@property (nonatomic,strong) NSMutableArray <GiftInfoModel *> *datasource;
///普通礼物的数据源
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftArray;
/////幸运礼物的数据源
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftLuckyArray;
///贵族礼物的数据源
@property (nonatomic, strong) NSArray<GiftInfoModel *> *giftNobleArray;
///周星礼物的数据源
@property (nonatomic, strong) NSArray<GiftInfoModel *> *giftWeekStarArray;
/////背包礼物的数据源
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftPackArray;
///涂鸦礼物数据源
@property (nonatomic,strong) NSArray<GiftInfoModel *> *giftGraffitiArray;
///个播礼物数据源
@property (nonatomic,strong) NSArray<GiftInfoModel *> *anchorArray;
///总的价值
@property (nonatomic,strong) NSAttributedString *totalAttribute;
///当前展示的数据的类型
@property (nonatomic,assign) GiftSegmentType segmentType;
///最后一次选中的礼物
@property (nonatomic,strong) GiftInfoModel *lastSelectGift;
@property (nonatomic, assign) NSInteger selectIndex;
///当前选中的page
@property (nonatomic,assign) NSInteger selectCurrentPage;
@end
@implementation XPGiftInfoView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Response
- (void)didClickGiftSegmentAction:(UIButton *)sender {
self.normalGiftButton.selected = NO;
self.luckyGiftButton.selected = NO;
self.nobleGiftButton.selected = NO;
self.packGiftButton.selected = NO;
self.weekStarButton.selected = NO;
self.graffitiButton.selected = NO;
self.anchorButton.selected = NO;
sender.selected = !sender.selected;
self.segmentType = sender.tag;
}
#pragma mark - Public Method
- (void)updatePackSource:(GiftReceiveInfoModel *)giftReceiveInfo numberUser:(NSInteger)numberUser {
GiftInfoModel * giftInfo = [self findGiftInfoByGiftId:giftReceiveInfo.giftId.integerValue];
giftInfo.count -= giftReceiveInfo.giftNum * numberUser;
if (giftInfo.count == 0) {
[self.datasource removeObject:giftInfo];
}
[self.giftcollectionView reloadData];
}
- (void)giftHeadTypeHadChange:(NSInteger)headType {
if (headType == 1) {
[self.graffitiButton removeFromSuperview];
[self.segmentStackView addArrangedSubview:self.normalGiftButton];
[self.segmentStackView addArrangedSubview:self.nobleGiftButton];
[self.segmentStackView addArrangedSubview:self.luckyGiftButton];
[self.segmentStackView addArrangedSubview:self.weekStarButton];
if(self.roomType == RoomType_Anchor) {
[self didClickGiftSegmentAction:self.anchorButton];
}
if(self.segmentType != GiftSegmentType_Pack) {
[self didClickGiftSegmentAction:self.normalGiftButton];
}
} else {
[self.normalGiftButton removeFromSuperview];
[self.luckyGiftButton removeFromSuperview];
[self.nobleGiftButton removeFromSuperview];
[self.weekStarButton removeFromSuperview];
[self.anchorButton removeFromSuperview];
[self.segmentStackView addArrangedSubview:self.graffitiButton];
if(self.segmentType != GiftSegmentType_Pack) {
[self didClickGiftSegmentAction:self.graffitiButton];
}
}
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.scrollView];
[self addSubview:self.giftStackView];
[self addSubview:self.packGiftButton];
[self addSubview:self.totalValueLabel];
[self.scrollView addSubview:self.segmentStackView];
///分段控制
[self.segmentStackView addArrangedSubview:self.normalGiftButton];
[self.segmentStackView addArrangedSubview:self.nobleGiftButton];
[self.segmentStackView addArrangedSubview:self.luckyGiftButton];
[self.segmentStackView addArrangedSubview:self.weekStarButton];
[self.segmentStackView addArrangedSubview:self.anchorButton];
///礼物
[self.giftStackView addArrangedSubview:self.giftcollectionView];
[self.giftStackView addArrangedSubview:self.pageController];
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30 + 108 * 2 + 10 + 10 + 15);
}];
[self.segmentStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.leading.trailing.height.mas_equalTo(self.scrollView);
}];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self).mas_offset(15);
make.right.mas_equalTo(self.packGiftButton.mas_left);
make.top.mas_equalTo(self);
make.height.mas_equalTo(30);
}];
[self.packGiftButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-15);
make.centerY.height.mas_equalTo(self.scrollView);
make.width.mas_equalTo(30);
}];
[self.totalValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.packGiftButton.mas_left).mas_offset(-6);
make.centerY.mas_equalTo(self.packGiftButton);
}];
[self.giftStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.segmentStackView.mas_bottom).offset(10);
make.left.right.mas_equalTo(self);
make.height.mas_equalTo(108 * 2 + 20);
}];
[self.pageController mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(10);
}];
}
- (void)resetSelectGift:(NSArray<GiftInfoModel *> *)array {
for (GiftInfoModel * gift in array) {
gift.isSelected = NO;
}
}
- (void)createPackTotalValueAttribute {
__block NSInteger giftTotal = 0;
[self.packOriginArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:GiftInfoModel.class]) {
GiftInfoModel *gift = (GiftInfoModel *)obj;
giftTotal += gift.count * gift.goldPrice;
}
}];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"总价值:" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[ThemeColor textThirdColor]}];
[str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",[self countFormatCoinStr:giftTotal]] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[ThemeColor appMainColor]}]];
NSTextAttachment *attachImage = [[NSTextAttachment alloc] init];
attachImage.image = [UIImage imageNamed:@"gift_diamond"];
attachImage.bounds = CGRectMake(0, 0, 9, 9);
[str appendAttributedString:[[NSMutableAttributedString alloc] initWithAttributedString:[NSAttributedString attributedStringWithAttachment:attachImage]]];
self.totalAttribute = str;
}
/**
将数量格式化为字符串 万之后用xx.xxW显示并保留小数点2位最多显示9999W+
@param number 数值
@return 格式化后的字符串
*/
- (NSString *)countFormatCoinStr:(NSInteger)number {
NSString *numStr = [NSString stringWithFormat:@"%li", number];
NSInteger num = number;
if (num > 99990000) {
numStr = @"9999W+";
} else if (num >= 10000) {
CGFloat numF = num / 10000.0;
numStr = [NSString stringWithFormat:@"%.2fW+", numF];
}
return numStr;
}
- (void)dealSelectGift:(GiftInfoModel *)giftInfo {
self.lastSelectGift = giftInfo;
if (self.segmentType == GiftSegmentType_Pack) {
giftInfo.sourceType = GiftSourceType_Pack;
} else {
giftInfo.sourceType = GiftSourceType_Normal;
}
giftInfo.isSelected = YES;
if (self.segmentType == GiftSegmentType_WeekStar) {
if (self.delegate && [self.delegate respondsToSelector:@selector(xpGiftInfoViewDidClickWeekStarGift:)]) {
[self.delegate xpGiftInfoViewDidClickWeekStarGift:giftInfo];
}
}
}
// 根据礼物id查找
- (GiftInfoModel *)findGiftInfoByGiftId:(NSInteger)giftId {
for (int i=0; i<self.datasource.count ; i++) {
GiftInfoModel *giftInfo = [self.datasource objectAtIndex:i];
if (giftInfo.giftId == giftId) {
return giftInfo;
}
}
return nil;
}
#pragma mark - scrollviewdelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.giftcollectionView) {
CGFloat offX = scrollView.contentOffset.x;
CGFloat width = CGRectGetWidth(scrollView.frame);
self.pageController.currentPage = ceilf(offX/width);
}
}
#pragma mark - UICollectionViewDelegate And UICollectionDatasource
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.segmentType == GiftSegmentType_Pack && self.datasource.count == 0) {
return CGSizeMake(KScreenWidth, 105 * 2 + 10);
}
if (self.segmentType == GiftSegmentType_WeekStar) {
return CGSizeMake(KScreenWidth, 105 * 2 + 10);
}
CGFloat itemWidth = (CGFloat)(KScreenWidth - 15 * 2 - 5 * 3) / (CGFloat)4;
return CGSizeMake(itemWidth, 108);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.segmentType == GiftSegmentType_Pack && self.datasource.count == 0) {
return 1;
}
if (self.segmentType == GiftSegmentType_WeekStar) {
return 1;
}
return self.datasource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if ((self.segmentType ==GiftSegmentType_Pack || self.segmentType == GiftSegmentType_WeekStar) && self.datasource.count == 0) {
XPGiftEmptyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftEmptyCollectionViewCell class]) forIndexPath:indexPath];
cell.emptyTitle = @"暂时木有礼物~";
return cell;
}
if (self.segmentType == GiftSegmentType_WeekStar) {
XPGiftWeekStarCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftWeekStarCollectionViewCell class]) forIndexPath:indexPath];
cell.delegate = self;
cell.weekStarGiftList = self.datasource;
return cell;
}
XPGiftItemCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftItemCollectionViewCell class]) forIndexPath:indexPath];
GiftInfoModel * giftInfo;
giftInfo= [self.datasource objectAtIndex:indexPath.item];
cell.curUserNobleLevel = self.curUserNobleLevel;
cell.giftInfo = giftInfo;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
[self resetSelectGift:self.datasource];
GiftInfoModel * giftInfo= [self.datasource objectAtIndex:indexPath.item];
[self dealSelectGift:giftInfo];
[self.giftcollectionView reloadData];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickItem:type:)]) {
[self.delegate xPGiftInfoView:self didClickItem:giftInfo type:self.segmentType];
}
}
}
#pragma mark - XPGiftWeekStarCollectionViewCellDelegate
- (void)xPGiftWeekStarCollectionViewCell:(XPGiftWeekStarCollectionViewCell *)view didSelectGift:(GiftInfoModel *)giftInfo {
[self dealSelectGift:giftInfo];
}
#pragma mark - Getters And Setters
- (void)setRoomType:(RoomType)roomType {
_roomType = roomType;
if (_roomType == RoomType_Anchor) {
self.anchorButton.hidden = NO;
}
}
- (void)setSegmentType:(GiftSegmentType)segmentType {
if (segmentType == _segmentType) {
return;
}
[_datasource removeAllObjects];
_segmentType = segmentType;
[self resetSelectGift:self.giftArray];
[self resetSelectGift:self.packOriginArray];
[self resetSelectGift:self.giftLuckyArray];
[self resetSelectGift:self.giftNobleArray];
[self resetSelectGift:self.giftWeekStarArray];
[self resetSelectGift:self.giftGraffitiArray];
[self resetSelectGift:self.anchorArray];
self.totalValueLabel.hidden = YES;
switch (_segmentType) {
case GiftSegmentType_Normal:
[self.datasource addObjectsFromArray:self.giftArray];
break;
case GiftSegmentType_Lucky:
[self.datasource addObjectsFromArray:self.giftLuckyArray];
break;
case GiftSegmentType_Noble: {
[self.datasource addObjectsFromArray:self.giftNobleArray];
}
break;
case GiftSegmentType_WeekStar: {
[self.datasource addObjectsFromArray:self.giftWeekStarArray];
}
break;
case GiftSegmentType_Pack:
{
[self.datasource addObjectsFromArray:self.packOriginArray];
self.totalValueLabel.hidden = NO;
self.totalValueLabel.attributedText= self.totalAttribute;
}
break;
case GiftSegmentType_Graffiti:
[self.datasource addObjectsFromArray:self.giftGraffitiArray];
break;
case GiftSegmentType_Anchor:
[self.datasource addObjectsFromArray:self.anchorArray];
break;
default:
[self.datasource addObjectsFromArray:self.giftArray];
break;
}
NSInteger currentPage = 0;
if (self.datasource.count > 0) {
if (self.defaultSelectGiftId.length && (self.segmentType == GiftSegmentType_Normal | self.segmentType == GiftSegmentType_Pack)) {
for (int i = 0 ; i <self.datasource.count; i++) {
GiftInfoModel * gift = [self.datasource objectAtIndex:i];
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
[self dealSelectGift:gift];
self.selectIndex = [self.datasource indexOfObject:gift];
NSInteger page = i / 8;
currentPage = page;
break;
}
}
} else {
GiftInfoModel * gift = [self.datasource firstObject];
[self dealSelectGift:gift];
}
}
NSInteger page = 0;
if (self.datasource.count % 8 == 0) { //刚好满页
page = self.datasource.count / 8;
} else {
page = self.datasource.count / 8 + 1;
}
self.pageController.hidden = page <= 1 || _segmentType == GiftSegmentType_WeekStar;
[self.pageController setNumberOfPages:page];
self.pageController.currentPage = currentPage;
self.selectCurrentPage = currentPage;
[self.giftcollectionView reloadData];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickSegment:)]) {
[self.delegate xPGiftInfoView:self didClickSegment:_segmentType];
}
if (self.segmentType != GiftSegmentType_Graffiti && self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickItem:type:)]) {
[self.delegate xPGiftInfoView:self didClickItem:self.lastSelectGift type:_segmentType];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.giftcollectionView setContentOffset:CGPointMake(self.selectCurrentPage * KScreenWidth, 0) animated:NO];;
});
}
- (void)setNormalOriginArray:(NSArray *)normalOriginArray {
_normalOriginArray = normalOriginArray;
NSMutableArray * luckyArray = [NSMutableArray array];
NSMutableArray * normaleArray = [NSMutableArray array];
NSMutableArray * nobleArray = [NSMutableArray array];
NSMutableArray * weekStarArray = [NSMutableArray array];
NSMutableArray * graffiti = [NSMutableArray array];
NSMutableArray * anchor = [NSMutableArray array];
[_normalOriginArray enumerateObjectsUsingBlock:^(GiftInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.giftType == GiftType_Lucky) {
[luckyArray addObject:obj];
} else if(obj.giftType == GiftType_Game) {
[normaleArray addObject:obj];
} else if (obj.giftType == GiftType_Noble) {
[nobleArray addObject:obj];
} else if (obj.giftType == GiftType_WeekStar) {
[weekStarArray addObject:obj];
} else if (obj.giftType == GiftType_Graffiti) {
[graffiti addObject:obj];
}else if (obj.giftType == GiftType_Anchor) {
[anchor addObject:obj];
}
}];
self.giftArray = normaleArray;
self.giftLuckyArray = luckyArray;
self.giftNobleArray = nobleArray;
self.giftWeekStarArray = weekStarArray;
self.giftGraffitiArray = graffiti;
self.anchorArray = anchor;
if (self.defaultSelectGiftId.length) {
for (GiftInfoModel *gift in self.normalOriginArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Normal;
break;
}
}
for (GiftInfoModel *gift in self.giftLuckyArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Lucky;
break;
}
}
for (GiftInfoModel *gift in self.giftNobleArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Noble;
break;
}
}
for (GiftInfoModel *gift in self.giftWeekStarArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_WeekStar;
break;
}
}
for (GiftInfoModel *gift in self.giftGraffitiArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Graffiti;
break;
}
}
for (GiftInfoModel *gift in self.anchorArray) {
if (gift.giftId == [self.defaultSelectGiftId integerValue]) {
self.segmentType = GiftSegmentType_Anchor;
break;
}
}
} else {
self.segmentType = GiftSegmentType_Normal;
}
}
- (void)setPackOriginArray:(NSArray *)packOriginArray {
_packOriginArray = packOriginArray;
[self createPackTotalValueAttribute];
}
- (void)setCurUserNobleLevel:(NSInteger)curUserNobleLevel {
_curUserNobleLevel = curUserNobleLevel;
[self.giftcollectionView reloadData];
}
- (void)setUsingplaceType:(SendGiftType)usingplaceType {
_usingplaceType = usingplaceType;
if (_usingplaceType == SendGiftType_User) {
self.luckyGiftButton.hidden = YES;
self.graffitiButton.hidden = YES;
self.anchorButton.hidden = YES;
}
}
- (void)setDefaultSelectGiftId:(NSString *)defaultSelectGiftId {
_defaultSelectGiftId = defaultSelectGiftId;
}
- (UIStackView *)segmentStackView {
if (!_segmentStackView) {
_segmentStackView = [[UIStackView alloc] init];
_segmentStackView.axis = UILayoutConstraintAxisHorizontal;
_segmentStackView.distribution = UIStackViewDistributionFill;
_segmentStackView.alignment = UIStackViewAlignmentCenter;
_segmentStackView.spacing = 10;
_segmentStackView.backgroundColor = [UIColor clearColor];
}
return _segmentStackView;
}
- (UIStackView *)giftStackView {
if (!_giftStackView) {
_giftStackView = [[UIStackView alloc] init];
_giftStackView.axis = UILayoutConstraintAxisVertical;
_giftStackView.distribution = UIStackViewDistributionFill;
_giftStackView.alignment = UIStackViewAlignmentFill;
_giftStackView.spacing = 0;
}
return _giftStackView;
}
- (UIButton *)normalGiftButton {
if (!_normalGiftButton) {
_normalGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_normalGiftButton setTitle:@"礼物" forState:UIControlStateNormal];
[_normalGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_normalGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_normalGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_normalGiftButton.tag = GiftSegmentType_Normal;
_normalGiftButton.selected = YES;
[_normalGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _normalGiftButton;
}
- (UIButton *)luckyGiftButton {
if (!_luckyGiftButton) {
_luckyGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_luckyGiftButton setTitle:@"幸运" forState:UIControlStateNormal];
[_luckyGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_luckyGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_luckyGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_luckyGiftButton.tag = GiftSegmentType_Lucky;
_luckyGiftButton.selected = NO;
[_luckyGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _luckyGiftButton;
}
- (UIButton *)nobleGiftButton {
if (!_nobleGiftButton) {
_nobleGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_nobleGiftButton setTitle:@"贵族" forState:UIControlStateNormal];
[_nobleGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_nobleGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_nobleGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_nobleGiftButton.tag = GiftSegmentType_Noble;
_nobleGiftButton.selected = NO;
[_nobleGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _nobleGiftButton;
}
- (UIButton *)weekStarButton {
if (!_weekStarButton) {
_weekStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_weekStarButton setTitle:@"周星" forState:UIControlStateNormal];
[_weekStarButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_weekStarButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_weekStarButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_weekStarButton.tag = GiftSegmentType_WeekStar;
_weekStarButton.selected = NO;
[_weekStarButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _weekStarButton;
}
- (UIButton *)packGiftButton {
if (!_packGiftButton) {
_packGiftButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_packGiftButton setTitle:@"背包" forState:UIControlStateNormal];
[_packGiftButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_packGiftButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_packGiftButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_packGiftButton.tag = GiftSegmentType_Pack;
_packGiftButton.selected = NO;
[_packGiftButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _packGiftButton;
}
- (UIButton *)graffitiButton {
if (!_graffitiButton) {
_graffitiButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_graffitiButton setTitle:@"涂鸦礼物" forState:UIControlStateNormal];
[_graffitiButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_graffitiButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_graffitiButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_graffitiButton.tag = GiftSegmentType_Graffiti;
_graffitiButton.selected = NO;
[_graffitiButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _graffitiButton;
}
- (UIButton *)anchorButton {
if (!_anchorButton) {
_anchorButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_anchorButton setTitle:@"个播" forState:UIControlStateNormal];
[_anchorButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected];
[_anchorButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal];
_anchorButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_anchorButton.tag = GiftSegmentType_Anchor;
_anchorButton.selected = NO;
_anchorButton.hidden = YES;
[_anchorButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _anchorButton;
}
- (UILabel *)totalValueLabel {
if (!_totalValueLabel) {
_totalValueLabel = [[UILabel alloc] init];
}
return _totalValueLabel;
}
- (UICollectionView *)giftcollectionView{
if (!_giftcollectionView) {
XPGiftCollectionViewFlowLayout *layout = [[XPGiftCollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 5;
layout.minimumInteritemSpacing = 5;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_giftcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_giftcollectionView.dataSource = self;
_giftcollectionView.delegate = self;
_giftcollectionView.backgroundColor = [UIColor clearColor];
_giftcollectionView.pagingEnabled = YES;
[_giftcollectionView registerClass:[XPGiftItemCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftItemCollectionViewCell class])];
[_giftcollectionView registerClass:[XPGiftEmptyCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftEmptyCollectionViewCell class])];
[_giftcollectionView registerClass:[XPGiftWeekStarCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPGiftWeekStarCollectionViewCell class])];
_giftcollectionView.showsHorizontalScrollIndicator = NO;
}
return _giftcollectionView;
}
- (UIPageControl *)pageController {
if (!_pageController) {
_pageController = [[UIPageControl alloc] init];
_pageController.currentPageIndicatorTintColor = [ThemeColor giftPageIndicatorColor];
}
return _pageController;
}
- (NSMutableArray<GiftInfoModel *> *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
- (UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.backgroundColor = [UIColor clearColor];
_scrollView.showsHorizontalScrollIndicator = NO;
}
return _scrollView;
}
@end