// // XPGiftMiddleView.m // xplan-ios // // Created by 冯硕 on 2021/11/9. // #import "XPGiftInfoView.h" ///Third #import ///Tool #import "XPMacro.h" #import "XPHtmlUrl.h" #import "ThemeColor+SendGift.h" #import "NSArray+Safe.h" #import "UIImage+Utils.h" ///Model #import "GiftInfoModel.h" #import "GiftReceiveInfoModel.h" #import "RoomInfoModel.h" ///View #import "XPGiftItemCollectionViewCell.h" #import "XPGiftEmptyCollectionViewCell.h" #import "XPGiftWeekStarCollectionViewCell.h" #import "XPGiftCollectionViewFlowLayout.h" #import "XPPrivilegeCardGiftCell.h" static NSString *kSendGiftViewHidePunishNewIcon = @"kSendGiftViewHidePunishNewIcon";///是否隐藏惩罚礼物“新”标识 @interface XPGiftInfoView () ///滚动的容器 @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 *punishButton; ///特权卡 @property(nonatomic,strong) UIButton *privilegeBtton; ///新标识图标 @property (nonatomic, strong) UIImageView *freshIconImage; ///个播礼物 @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 *datasource; ///普通礼物的数据源 @property (nonatomic,strong) NSArray *giftArray; /////幸运礼物的数据源 @property (nonatomic,strong) NSArray *giftLuckyArray; ///贵族礼物的数据源 @property (nonatomic, strong) NSArray *giftNobleArray; ///周星礼物的数据源 @property (nonatomic, strong) NSArray *giftWeekStarArray; /////背包礼物的数据源 @property (nonatomic,strong) NSArray *giftPackArray; ///涂鸦礼物数据源 @property (nonatomic,strong) NSArray *giftGraffitiArray; ///个播礼物数据源 @property (nonatomic,strong) NSArray *anchorArray; ///惩罚礼物数据源 @property (nonatomic, strong) NSArray *punishArray; ///总的价值 @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; //////最后一次选中的特权卡 @property (nonatomic,strong) XPPrivilegeCardItemModel *lastSelectPrivilege; @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; self.punishButton.selected = NO; self.privilegeBtton.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.punishButton removeFromSuperview]; [self.freshIconImage removeFromSuperview]; self.freshIconImage = nil; [self.segmentStackView addArrangedSubview:self.normalGiftButton]; [self.segmentStackView addArrangedSubview:self.nobleGiftButton]; [self.segmentStackView addArrangedSubview:self.luckyGiftButton]; [self.segmentStackView addArrangedSubview:self.weekStarButton]; if(self.roomInfo){ if(self.roomInfo.hasRoomPrivilegeCard == YES){ [self.segmentStackView addArrangedSubview:self.privilegeBtton]; } } if(self.roomType == RoomType_Anchor) { [self.segmentStackView addArrangedSubview:self.anchorButton]; [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]; [self.segmentStackView addArrangedSubview:self.punishButton]; BOOL hiden = [[NSUserDefaults standardUserDefaults] boolForKey:kSendGiftViewHidePunishNewIcon]; if(!hiden) { [self addSubview:self.freshIconImage]; [self.freshIconImage mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.punishButton.mas_right).mas_offset(-5); make.bottom.mas_equalTo(self.punishButton.mas_top).mas_offset(5); make.size.mas_equalTo(CGSizeMake(24, 10)); }]; } 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 + 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)resetSelectPrivilege:(NSArray *)array { for (XPPrivilegeCardItemModel * gift in array) { gift.isSelected = NO; } } - (void)resetSelectGift:(NSArray *)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: self.usingplaceType == SendGiftType_Room ? [ThemeColor textThirdColor] : [ThemeColor colorWithHexString:@"#878B9C"]}]; [str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",[self countFormatCoinStr:giftTotal]] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:self.usingplaceType == SendGiftType_Room ? [ThemeColor appMainColor] : [ThemeColor colorWithHexString:@"#282828"]}]]; NSTextAttachment *attachImage = [[NSTextAttachment alloc] init]; attachImage.image = [UIImage imageNamed:@"common_diamond"]; attachImage.bounds = CGRectMake(0, 0, 10, 10); [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; } // 根据礼物id查找 - (GiftInfoModel *)findGiftInfoByGiftId:(NSInteger)giftId { for (int i=0; i 0) { [self resetSelectGift:self.datasource]; GiftInfoModel * giftInfo= [self.datasource safeObjectAtIndex1: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)setPrivilegeArray:(NSArray *)privilegeArray{ _privilegeArray = privilegeArray; if(_privilegeArray.count > 0){ XPPrivilegeCardItemModel *cardModel = _privilegeArray.firstObject; cardModel.isSelected = YES; } } - (void)setRoomInfo:(RoomInfoModel *)roomInfo{ _roomInfo = roomInfo; if(_roomInfo){ if(_roomInfo.hasRoomPrivilegeCard == YES){ [self.segmentStackView addArrangedSubview:self.privilegeBtton]; } } } - (void)setSegmentType:(GiftSegmentType)segmentType { if (segmentType == _segmentType) { return; } _segmentType = segmentType; self.totalValueLabel.hidden = YES; if(_segmentType == GiftSegmentType_Privilege){ self.packGiftButton.hidden = YES; [self resetSelectPrivilege:self.privilegeArray]; if(_privilegeArray.count > 0){ XPPrivilegeCardItemModel *cardModel = _privilegeArray.firstObject; self.lastSelectPrivilege = cardModel; if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickPrivilegeItem:type:)]) { [self.delegate xPGiftInfoView:self didClickPrivilegeItem:cardModel type:self.segmentType]; } cardModel.isSelected = YES; } [self.giftcollectionView reloadData]; if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftInfoView:didClickSegment:)]) { [self.delegate xPGiftInfoView:self didClickSegment:_segmentType]; } return; } self.packGiftButton.hidden = NO; [_datasource removeAllObjects]; [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 resetSelectGift:self.punishArray]; 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; case GiftSegmentType_Punish: { [self.datasource addObjectsFromArray:self.punishArray]; [self.freshIconImage removeFromSuperview]; self.freshIconImage = nil; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kSendGiftViewHidePunishNewIcon]; [[NSUserDefaults standardUserDefaults] synchronize]; } 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 0 ? self.giftArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_Lucky) { self.lastSelectGift = self.giftLuckyArray.count > 0 ? self.giftLuckyArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_WeekStar) { self.lastSelectGift = self.giftWeekStarArray.count > 0 ? self.giftWeekStarArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_Noble) { self.lastSelectGift = self.giftNobleArray.count > 0 ? self.giftNobleArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_Graffiti) { self.lastSelectGift = self.giftGraffitiArray.count > 0 ? self.giftGraffitiArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_Anchor) { self.lastSelectGift = self.anchorArray.count > 0 ? self.anchorArray.firstObject : nil; }else if (_segmentType == GiftSegmentType_Punish) { self.lastSelectGift = self.punishArray.count > 0 ? self.punishArray.firstObject : nil; } if(self.lastSelectGift){ self.defaultSelectGiftId = self.defaultSelectGiftId == nil ? @(self.lastSelectGift.giftId).stringValue : self.defaultSelectGiftId; }else{ if(_segmentType == GiftSegmentType_Normal){ self.segmentType = GiftSegmentType_Normal; }else if (_segmentType == GiftSegmentType_Lucky) { self.segmentType = GiftSegmentType_Lucky; }else if (_segmentType == GiftSegmentType_WeekStar) { self.segmentType = GiftSegmentType_WeekStar; }else if (_segmentType == GiftSegmentType_Noble) { self.segmentType = GiftSegmentType_Noble; }else if (_segmentType == GiftSegmentType_Graffiti) { self.segmentType = GiftSegmentType_Graffiti; }else if (_segmentType == GiftSegmentType_Anchor) { self.segmentType = GiftSegmentType_Anchor; }else if (_segmentType == GiftSegmentType_Punish) { self.segmentType = GiftSegmentType_Punish; }else{ self.segmentType = GiftSegmentType_Normal; } return; } if(_segmentType == GiftSegmentType_Privilege){ return; } 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; } } for (GiftInfoModel *gift in self.punishArray) { if (gift.giftId == [self.defaultSelectGiftId integerValue]) { self.segmentType = GiftSegmentType_Punish; 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; self.punishButton.hidden = YES; [self.nobleGiftButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateSelected]; [self.nobleGiftButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal]; [self.normalGiftButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateSelected]; [self.normalGiftButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal]; [self.weekStarButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateSelected]; [self.weekStarButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal]; [self.packGiftButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateSelected]; [self.packGiftButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal]; } } - (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 *)privilegeBtton { if (!_privilegeBtton) { _privilegeBtton = [UIButton buttonWithType:UIButtonTypeCustom]; [_privilegeBtton setTitle:@"特权卡" forState:UIControlStateNormal]; [_privilegeBtton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected]; [_privilegeBtton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal]; _privilegeBtton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold]; _privilegeBtton.tag = GiftSegmentType_Privilege; _privilegeBtton.selected = NO; [_privilegeBtton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside]; } return _privilegeBtton; } - (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 *)punishButton { if (!_punishButton) { _punishButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_punishButton setTitle:@"惩罚礼物" forState:UIControlStateNormal]; [_punishButton setTitleColor:[ThemeColor giftSegmentSelectTitleColor] forState:UIControlStateSelected]; [_punishButton setTitleColor:[ThemeColor giftSegmentNormalTitleColor] forState:UIControlStateNormal]; _punishButton.titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold]; _punishButton.tag = GiftSegmentType_Punish; _punishButton.selected = NO; [_punishButton addTarget:self action:@selector(didClickGiftSegmentAction:) forControlEvents:UIControlEventTouchUpInside]; } return _punishButton; } - (UIImageView *)freshIconImage { if (!_freshIconImage) { _freshIconImage = [[UIImageView alloc] init]; _freshIconImage.image = [UIImage imageNamed:@"gift_type_newIcon"]; } return _freshIconImage; } - (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) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; _giftcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _giftcollectionView.dataSource = self; _giftcollectionView.delegate = self; _giftcollectionView.backgroundColor = [UIColor clearColor]; [_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 registerClass:[XPPrivilegeCardGiftCell class] forCellWithReuseIdentifier:NSStringFromClass([XPPrivilegeCardGiftCell class])]; } return _giftcollectionView; } //- (UIPageControl *)pageController { // if (!_pageController) { // _pageController = [[UIPageControl alloc] init]; // _pageController.currentPageIndicatorTintColor = [ThemeColor giftPageIndicatorColor]; // } // return _pageController; //} - (NSMutableArray *)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