Files
keyboard/keyBoard/Class/Pay/VC/KBVipPay.m

496 lines
22 KiB
Mathematica
Raw Normal View History

2025-11-14 18:43:08 +08:00
//
// KBVipPay.m
// keyBoard
//
// Created by Mac on 2025/11/14.
//
#import "KBVipPay.h"
2025-11-14 19:48:15 +08:00
#import "KBVipPayHeaderView.h"
#import "KBVipSubscribeCell.h"
#import "KBVipReviewListCell.h"
2025-12-12 14:54:45 +08:00
#import "PayVM.h"
#import "KBPayProductModel.h"
#import "KBBizCode.h"
2025-12-16 13:49:08 +08:00
#import "keyBoard-Swift.h"
2025-11-14 18:43:08 +08:00
2025-11-14 19:48:15 +08:00
static NSString * const kKBVipHeaderId = @"kKBVipHeaderId";
static NSString * const kKBVipSubscribeCellId = @"kKBVipSubscribeCellId";
static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
@interface KBVipPay () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView; //
2025-12-12 14:54:45 +08:00
@property (nonatomic, strong) NSArray<KBPayProductModel *> *plans; //
2025-11-14 19:48:15 +08:00
@property (nonatomic, assign) NSInteger selectedIndex; //
@property (nonatomic, strong) UIButton *closeButton; //
2025-12-16 16:25:50 +08:00
@property (nonatomic, strong) UIButton *restoreButton;
2025-11-14 23:09:04 +08:00
@property (nonatomic, strong) UIImageView *bgImageView; //
2025-11-15 00:33:29 +08:00
// Header
@property (nonatomic, strong) KBVipPayHeaderView *sizingHeader;
@property (nonatomic, assign) CGFloat headerHeight;
2025-11-15 14:27:41 +08:00
//
@property (nonatomic, strong) UIButton *payButton; //
@property (nonatomic, strong) UILabel *agreementLabel; //
@property (nonatomic, strong) UIButton *agreementButton; // Embership Agreement
2025-12-12 14:54:45 +08:00
@property (nonatomic, strong) PayVM *payVM;
2025-12-17 16:22:41 +08:00
@property (nonatomic, copy, nullable) NSString *pendingProductId;
@property (nonatomic, assign) BOOL pendingAutoPurchase;
@property (nonatomic, assign) BOOL hasTriggeredAutoPurchase;
@property (nonatomic, assign) BOOL viewVisible;
2025-11-14 18:43:08 +08:00
@end
@implementation KBVipPay
- (void)viewDidLoad {
[super viewDidLoad];
2025-11-14 19:48:15 +08:00
//
// self.kb_titleLabel.text = @"VIP";
// self.kb_navView.backgroundColor = [UIColor clearColor];
2025-11-14 23:09:04 +08:00
self.view.backgroundColor = [UIColor colorWithHex:0xF6F7FB];
self.kb_enableCustomNavBar = NO;
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pay_vipbg_icon"]];
self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.view);
make.height.mas_equalTo(224);
}];
2025-12-12 14:54:45 +08:00
self.payVM = [PayVM new];
self.plans = @[];
self.selectedIndex = NSNotFound;
2025-11-14 23:09:04 +08:00
2025-11-14 19:48:15 +08:00
//
[self.view addSubview:self.collectionView];
2025-11-15 14:27:41 +08:00
// collectionView
[self.view addSubview:self.payButton];
[self.view addSubview:self.agreementLabel];
[self.view addSubview:self.agreementButton];
[self.payButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(24);
make.right.equalTo(self.view).offset(-24);
make.bottom.equalTo(self.agreementLabel.mas_top).offset(-14);
make.height.mas_equalTo(58);
}];
[self.agreementButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-KB_SAFE_BOTTOM - 15);
}];
[self.agreementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
2025-11-25 15:36:16 +08:00
make.bottom.equalTo(self.agreementButton.mas_top).offset(0);
2025-11-15 14:27:41 +08:00
}];
2025-11-14 19:48:15 +08:00
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-15 14:27:41 +08:00
make.left.right.equalTo(self.view);
2025-11-14 23:09:04 +08:00
make.top.equalTo(self.view).offset(0);
2025-11-15 14:27:41 +08:00
make.bottom.equalTo(self.payButton.mas_top).offset(-16);
2025-11-14 23:09:04 +08:00
}];
[self.view addSubview:self.closeButton];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT - 30);
make.left.equalTo(self.view).offset(15);
make.width.height.mas_equalTo(36);
2025-11-14 19:48:15 +08:00
}];
2025-12-16 16:25:50 +08:00
[self.view addSubview:self.restoreButton];
[self.restoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.closeButton);
make.right.equalTo(self.view).offset(-15);
make.width.mas_equalTo(123);
make.height.mas_equalTo(32);
}];
2025-11-14 19:48:15 +08:00
2025-11-15 00:33:29 +08:00
// Header
self.headerHeight = [self kb_calcHeaderHeightForWidth:KB_SCREEN_WIDTH];
2025-11-14 19:48:15 +08:00
[self.collectionView reloadData];
2025-12-12 14:54:45 +08:00
[self fetchSubscriptionPlans];
2025-11-14 19:48:15 +08:00
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
2025-12-17 16:22:41 +08:00
self.viewVisible = YES;
2025-12-12 14:54:45 +08:00
[self selectCurrentPlanAnimated:NO];
2025-12-17 16:22:41 +08:00
[self kb_triggerAutoPurchaseIfNeeded];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
self.viewVisible = NO;
}
#pragma mark - Deep Link Support
- (void)configureWithProductId:(NSString *)productId autoPurchase:(BOOL)autoPurchase {
self.pendingProductId = productId.length ? [productId copy] : nil;
self.pendingAutoPurchase = autoPurchase;
self.hasTriggeredAutoPurchase = NO;
[self kb_applyPendingPrefillIfNeeded];
[self kb_triggerAutoPurchaseIfNeeded];
2025-12-12 14:54:45 +08:00
}
#pragma mark - Data
- (void)fetchSubscriptionPlans {
__weak typeof(self) weakSelf = self;
[self.payVM fetchSubscriptionProductsNeedShow:YES completion:^(NSInteger sta, NSString * _Nullable msg, NSArray<KBPayProductModel *> * _Nullable products) {
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) self = weakSelf;
if (!self) { return; }
if (sta != KBBizCodeSuccess || ![products isKindOfClass:NSArray.class]) {
self.plans = @[];
self.selectedIndex = NSNotFound;
[self.collectionView reloadData];
NSString *tip = msg.length ? msg : KBLocalized(@"Failed to load products");
if (tip.length) { [KBHUD showInfo:tip]; }
return;
}
self.plans = products ?: @[];
self.selectedIndex = self.plans.count > 0 ? 0 : NSNotFound;
[self.collectionView reloadData];
2025-12-16 13:49:08 +08:00
[self prepareStoreKitWithPlans:self.plans];
2025-12-17 16:22:41 +08:00
[self kb_applyPendingPrefillIfNeeded];
2025-12-12 14:54:45 +08:00
[self selectCurrentPlanAnimated:NO];
2025-12-17 16:22:41 +08:00
[self kb_triggerAutoPurchaseIfNeeded];
2025-12-12 14:54:45 +08:00
});
}];
}
2025-12-16 13:49:08 +08:00
- (void)prepareStoreKitWithPlans:(NSArray<KBPayProductModel *> *)plans {
if (![plans isKindOfClass:NSArray.class] || plans.count == 0) { return; }
NSMutableArray<NSString *> *ids = [NSMutableArray array];
for (KBPayProductModel *plan in plans) {
if (![plan isKindOfClass:KBPayProductModel.class]) { continue; }
if (plan.productId.length) {
[ids addObject:plan.productId];
}
}
if (ids.count == 0) { return; }
[[KBStoreKitBridge shared] prepareWithProductIds:ids completion:nil];
}
2025-12-12 14:54:45 +08:00
- (void)selectCurrentPlanAnimated:(BOOL)animated {
if (self.selectedIndex == NSNotFound) { return; }
if (self.selectedIndex < 0 || self.selectedIndex >= self.plans.count) { return; }
2025-11-14 19:48:15 +08:00
NSIndexPath *ip = [NSIndexPath indexPathForItem:self.selectedIndex inSection:1];
if (!ip) { return; }
2025-12-12 14:54:45 +08:00
[self.collectionView selectItemAtIndexPath:ip animated:animated scrollPosition:UICollectionViewScrollPositionNone];
2025-11-14 19:48:15 +08:00
KBVipSubscribeCell *cell = (KBVipSubscribeCell *)[self.collectionView cellForItemAtIndexPath:ip];
2025-12-12 14:54:45 +08:00
if ([cell isKindOfClass:KBVipSubscribeCell.class]) {
[cell applySelected:YES animated:animated];
}
}
- (KBPayProductModel *)currentSelectedPlan {
if (self.selectedIndex == NSNotFound) { return nil; }
if (self.selectedIndex < 0 || self.selectedIndex >= self.plans.count) { return nil; }
id plan = self.plans[self.selectedIndex];
if (![plan isKindOfClass:KBPayProductModel.class]) { return nil; }
return plan;
}
2025-12-17 16:22:41 +08:00
- (void)kb_applyPendingPrefillIfNeeded {
if (self.pendingProductId.length == 0 || self.plans.count == 0) { return; }
__block NSInteger target = NSNotFound;
[self.plans enumerateObjectsUsingBlock:^(KBPayProductModel *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:KBPayProductModel.class]) { return; }
if ([obj.productId isEqualToString:self.pendingProductId]) {
target = (NSInteger)idx;
*stop = YES;
}
}];
if (target != NSNotFound) {
self.selectedIndex = target;
}
}
- (void)kb_triggerAutoPurchaseIfNeeded {
if (!self.pendingAutoPurchase || self.hasTriggeredAutoPurchase || !self.viewVisible) { return; }
if (![self currentSelectedPlan]) { return; }
self.hasTriggeredAutoPurchase = YES;
self.pendingAutoPurchase = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self onTapPayButton];
});
}
2025-12-12 14:54:45 +08:00
- (NSString *)displayTitleForPlan:(KBPayProductModel *)plan {
if (!plan) { return @""; }
if (plan.productDescription.length) { return plan.productDescription; }
NSString *name = plan.name ?: @"";
NSString *unit = plan.unit ?: @"";
if (name.length && unit.length) { return [NSString stringWithFormat:@"%@%@", name, unit]; }
if (name.length) { return name; }
if (unit.length) { return unit; }
return KBLocalized(@"Subscription");
2025-11-14 18:43:08 +08:00
}
2025-11-15 00:33:29 +08:00
#pragma mark - Header Height Calc
- (CGFloat)kb_calcHeaderHeightForWidth:(CGFloat)width {
if (width <= 0) { width = KB_SCREEN_WIDTH; }
if (!self.sizingHeader) {
self.sizingHeader = [[KBVipPayHeaderView alloc] initWithFrame:CGRectMake(0, 0, width, 1)];
}
//
self.sizingHeader.bounds = CGRectMake(0, 0, width, self.sizingHeader.bounds.size.height);
[self.sizingHeader setNeedsLayout];
[self.sizingHeader layoutIfNeeded];
CGSize size = [self.sizingHeader systemLayoutSizeFittingSize:CGSizeMake(width, UILayoutFittingCompressedSize.height)
withHorizontalFittingPriority:UILayoutPriorityRequired
verticalFittingPriority:UILayoutPriorityFittingSizeLevel];
return MAX(1, ceil(size.height));
}
2025-11-14 23:09:04 +08:00
#pragma mark - Action
- (void)onTapClose{
[self.navigationController popViewControllerAnimated:true];
}
2025-11-15 14:27:41 +08:00
#pragma mark - Bottom Actions
- (void)onTapPayButton {
2025-12-12 14:54:45 +08:00
KBPayProductModel *plan = [self currentSelectedPlan];
if (!plan) {
[KBHUD showInfo:KBLocalized(@"Please select a product")];
return;
}
NSString *productId = plan.productId;
if (productId.length == 0) {
[KBHUD showInfo:KBLocalized(@"Product unavailable")];
return;
}
[KBHUD show];
__weak typeof(self) weakSelf = self;
2025-12-16 13:49:08 +08:00
[[KBStoreKitBridge shared] purchaseWithProductId:productId completion:^(BOOL success, NSString * _Nullable message) {
__strong typeof(weakSelf) self = weakSelf;
2025-12-16 16:09:14 +08:00
// NSString *tip = message.length ? message : (success ? KBLocalized(@"Payment successful") : KBLocalized(@"Payment failed"));
2025-12-16 13:49:08 +08:00
[KBHUD dismiss];
2025-12-16 16:09:14 +08:00
// [KBHUD showInfo:tip];
[KBHUD showInfo:KBLocalized(message)];
2025-12-16 13:49:08 +08:00
if (!self || !success) { return; }
// UI
[self selectCurrentPlanAnimated:NO];
2025-12-12 14:54:45 +08:00
}];
2025-11-15 14:27:41 +08:00
}
- (void)agreementButtonAction{
2025-11-17 20:07:39 +08:00
[KBHUD showInfo:KBLocalized(@"Open agreement")];
2025-11-15 14:27:41 +08:00
}
2025-12-16 16:25:50 +08:00
- (void)onTapRestoreButton {
[KBHUD show];
__weak typeof(self) weakSelf = self;
[[KBStoreKitBridge shared] restorePurchasesWithCompletion:^(BOOL success, NSString * _Nullable message) {
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) self = weakSelf;
(void)self;
[KBHUD dismiss];
NSString *tip = message.length ? message : (success ? KBLocalized(@"Success") : KBLocalized(@"Failed"));
[KBHUD showInfo:tip];
});
}];
}
2025-11-14 19:48:15 +08:00
#pragma mark - UICollectionView DataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
// 012
return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (section == 1) { return self.plans.count; }
if (section == 2) { return 1; }
return 0; // 使 header
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1) {
KBVipSubscribeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kKBVipSubscribeCellId forIndexPath:indexPath];
2025-12-12 14:54:45 +08:00
if (indexPath.item < self.plans.count) {
KBPayProductModel *plan = self.plans[indexPath.item];
NSString *title = [self displayTitleForPlan:plan];
NSString *price = [plan priceDisplayText];
[cell configTitle:title price:price strike:nil];
[cell applySelected:(indexPath.item == self.selectedIndex) animated:NO];
} else {
[cell configTitle:@"" price:@"" strike:nil];
[cell applySelected:NO animated:NO];
}
2025-11-14 19:48:15 +08:00
return cell;
} else {
KBVipReviewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kKBVipReviewListCellId forIndexPath:indexPath];
return cell;
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
KBVipPayHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kKBVipHeaderId forIndexPath:indexPath];
return header;
}
return [UICollectionReusableView new];
}
#pragma mark - UICollectionView Delegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
2025-12-12 14:54:45 +08:00
if (indexPath.section != 1 || indexPath.item >= self.plans.count) { return; }
2025-11-14 19:48:15 +08:00
if (self.selectedIndex == indexPath.item) { return; }
NSInteger old = self.selectedIndex;
self.selectedIndex = indexPath.item;
KBVipSubscribeCell *newCell = (KBVipSubscribeCell *)[collectionView cellForItemAtIndexPath:indexPath];
[newCell applySelected:YES animated:YES];
if (old >= 0 && old < self.plans.count) {
NSIndexPath *oldIP = [NSIndexPath indexPathForItem:old inSection:1];
KBVipSubscribeCell *oldCell = (KBVipSubscribeCell *)[collectionView cellForItemAtIndexPath:oldIP];
[oldCell applySelected:NO animated:YES];
}
}
2025-11-14 18:43:08 +08:00
2025-11-14 19:48:15 +08:00
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
//
2025-12-12 14:54:45 +08:00
if (indexPath.section == 1 && indexPath.item < self.plans.count && [cell isKindOfClass:KBVipSubscribeCell.class]) {
2025-11-14 19:48:15 +08:00
BOOL sel = (indexPath.item == self.selectedIndex);
KBVipSubscribeCell *c = (KBVipSubscribeCell *)cell;
if (sel) {
[collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}
[c applySelected:sel animated:NO];
}
2025-11-14 18:43:08 +08:00
}
2025-11-14 19:48:15 +08:00
#pragma mark - FlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat w = KB_SCREEN_WIDTH - 32;
if (indexPath.section == 1) {
2025-11-14 23:09:04 +08:00
return CGSizeMake(w, KBFit(75 + 6));
2025-11-14 19:48:15 +08:00
} else {
return CGSizeMake(w, 140);
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (section == 0) {
2025-11-15 00:33:29 +08:00
// Header
CGFloat w = collectionView.bounds.size.width ?: KB_SCREEN_WIDTH;
if (self.headerHeight <= 1) { self.headerHeight = [self kb_calcHeaderHeightForWidth:w]; }
return CGSizeMake(w, self.headerHeight);
2025-11-14 19:48:15 +08:00
}
return CGSizeZero;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
if (section == 1) { return 14; }
return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
if (section == 1) {
2025-11-14 23:09:04 +08:00
// cell header
return UIEdgeInsetsMake(16, 16, 10, 16);
2025-11-14 19:48:15 +08:00
} else if (section == 2) {
return UIEdgeInsetsMake(10, 16, 20, 16);
}
return UIEdgeInsetsZero;
}
#pragma mark - Lazy
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
2025-11-15 00:33:29 +08:00
// 便 header
layout.sectionHeadersPinToVisibleBounds = NO;
2025-11-14 19:48:15 +08:00
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.alwaysBounceVertical = YES;
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_collectionView registerClass:KBVipPayHeaderView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kKBVipHeaderId];
[_collectionView registerClass:KBVipSubscribeCell.class forCellWithReuseIdentifier:kKBVipSubscribeCellId];
[_collectionView registerClass:KBVipReviewListCell.class forCellWithReuseIdentifier:kKBVipReviewListCellId];
}
return _collectionView;
}
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
2025-11-14 23:09:04 +08:00
[_closeButton setImage:[UIImage imageNamed:@"close_white2_icon"] forState:UIControlStateNormal];
2025-11-14 19:48:15 +08:00
[_closeButton addTarget:self action:@selector(onTapClose) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
2025-11-15 00:33:29 +08:00
2025-12-16 16:25:50 +08:00
- (UIButton *)restoreButton {
if (!_restoreButton) {
_restoreButton = [UIButton buttonWithType:UIButtonTypeCustom];
_restoreButton.backgroundColor = [[UIColor colorWithHex:0xF6F7FB] colorWithAlphaComponent:0.72];
_restoreButton.layer.cornerRadius = 8;
_restoreButton.layer.masksToBounds = YES;
UIImage *icon = [UIImage imageNamed:@"pay_resh_icon"];
[_restoreButton setImage:icon forState:UIControlStateNormal];
[_restoreButton setTitle:KBLocalized(@"Resume Purchase") forState:UIControlStateNormal];
[_restoreButton setTitleColor:[UIColor colorWithHex:0x02BEAC] forState:UIControlStateNormal];
_restoreButton.titleLabel.font = [KBFont medium:10];
_restoreButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 12);
_restoreButton.imageEdgeInsets = UIEdgeInsetsMake(0, -4, 0, 4);
_restoreButton.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, -6);
[_restoreButton addTarget:self action:@selector(onTapRestoreButton) forControlEvents:UIControlEventTouchUpInside];
}
return _restoreButton;
}
2025-11-15 14:27:41 +08:00
- (UIButton *)payButton {
if (!_payButton) {
_payButton = [UIButton buttonWithType:UIButtonTypeCustom];
2025-11-17 21:35:25 +08:00
[_payButton setTitle:KBLocalized(@"Recharge Now") forState:UIControlStateNormal];
2025-11-15 14:27:41 +08:00
[_payButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal];
2025-11-25 15:36:16 +08:00
// _payButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
_payButton.titleLabel.font = [KBFont medium:15];
2025-11-15 14:27:41 +08:00
UIImage *bg = [UIImage imageNamed:@"recharge_now_icon"];
if (bg) {
[_payButton setBackgroundImage:bg forState:UIControlStateNormal];
} else {
//
UIImage *fallback = [UIImage kb_gradientImageWithColors:@[[UIColor colorWithHex:0xC7F8F0], [UIColor colorWithHex:0xE8FFF6]] size:CGSizeMake(10, 58) direction:KBGradientDirectionLeftToRight];
[_payButton setBackgroundImage:[fallback resizableImageWithCapInsets:UIEdgeInsetsMake(29, 29, 29, 29) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal];
}
[_payButton addTarget:self action:@selector(onTapPayButton) forControlEvents:UIControlEventTouchUpInside];
}
return _payButton;
}
- (UILabel *)agreementLabel {
if (!_agreementLabel) {
_agreementLabel = [UILabel new];
_agreementLabel.text = @"By clicking \"Pay\", you indicate your agreement to the";
2025-11-25 15:36:16 +08:00
_agreementLabel.font = [KBFont regular:12];
2025-11-15 14:27:41 +08:00
_agreementLabel.textColor = [UIColor colorWithHex:KBBlackValue];
}
return _agreementLabel;
}
- (UIButton *)agreementButton {
if (!_agreementButton) {
_agreementButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_agreementButton setTitle:@"《Embership Agreement》" forState:UIControlStateNormal];
[_agreementButton setTitleColor:[UIColor colorWithHex:KBColorValue] forState:UIControlStateNormal];
2025-11-25 15:36:16 +08:00
_agreementButton.titleLabel.font = [KBFont regular:12];
2025-11-15 14:27:41 +08:00
[_agreementButton addTarget:self action:@selector(agreementButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _agreementButton;
}
2025-11-15 00:33:29 +08:00
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Header
CGFloat w = self.collectionView.bounds.size.width ?: KB_SCREEN_WIDTH;
CGFloat newH = [self kb_calcHeaderHeightForWidth:w];
if (fabs(newH - self.headerHeight) > 0.5) {
self.headerHeight = newH;
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
[layout invalidateLayout];
}
}
2025-11-14 18:43:08 +08:00
@end