Files
keyboard/keyBoard/Class/Shop/V/KBShopHeadView.m

316 lines
12 KiB
Mathematica
Raw Normal View History

2025-11-09 13:56:13 +08:00
//
// KBShopHeadView.m
// keyBoard
//
// Created by Mac on 2025/11/9.
//
#import "KBShopHeadView.h"
2025-11-17 14:53:23 +08:00
#import "KBJfPay.h"
2025-11-13 16:23:46 +08:00
@interface KBShopHeadView ()
//
@property (nonatomic, strong) UIView *containerView;
//
@property (nonatomic, strong) UILabel *titleLabel; // "Points\nMall"
@property (nonatomic, strong) UIImageView *yellowStarView; // shop_yellowxx_icon
2025-11-13 19:07:59 +08:00
@property (nonatomic, strong) UIImageView *yellowStarView2; // shop_yellowxx_icon
2025-11-13 16:23:46 +08:00
@property (nonatomic, strong) UIImageView *greenStarView; // 绿shop_greenxx_icon
2025-11-13 19:07:59 +08:00
@property (nonatomic, strong) UIImageView *greenStarView2; // 绿shop_greenxx_icon
@property (nonatomic, strong) UIImageView *greenStarView3; // 绿shop_greenxx_icon
2025-11-13 16:23:46 +08:00
//
@property (nonatomic, strong) UIImageView *bigCoinView; // shop_headbigBg_icon
//
@property (nonatomic, strong) UIView *infoCard; // 绿
@property (nonatomic, strong) UILabel *myPointsLabel; // "My Points"
@property (nonatomic, strong) UIImageView *smallCoinView; // shop_jb_icon
@property (nonatomic, strong) UILabel *amountLabel; // 88.00
@property (nonatomic, strong) UIButton *rechargeButton; // recharge_btn_bg
2025-11-09 13:56:13 +08:00
2025-11-13 15:34:56 +08:00
@end
2025-11-13 16:23:46 +08:00
2025-11-09 13:56:13 +08:00
@implementation KBShopHeadView
2025-11-13 16:23:46 +08:00
- (instancetype)initWithFrame:(CGRect)frame {
2025-11-13 14:11:44 +08:00
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
2025-11-13 16:23:46 +08:00
//
[self addSubview:self.containerView];
[self.containerView addSubview:self.titleLabel];
2025-11-13 19:07:59 +08:00
[self.containerView addSubview:self.bigCoinView];
2025-11-13 16:23:46 +08:00
[self.containerView addSubview:self.yellowStarView];
2025-11-13 19:07:59 +08:00
[self.containerView addSubview:self.yellowStarView2];
2025-11-13 16:23:46 +08:00
[self.containerView addSubview:self.greenStarView];
2025-11-13 19:07:59 +08:00
[self.containerView addSubview:self.greenStarView2];
[self.containerView addSubview:self.greenStarView3];
2025-11-13 16:23:46 +08:00
[self.containerView addSubview:self.infoCard];
[self.infoCard addSubview:self.myPointsLabel];
[self.infoCard addSubview:self.smallCoinView];
[self.infoCard addSubview:self.amountLabel];
[self.infoCard addSubview:self.rechargeButton];
//
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(16);
make.right.equalTo(self).offset(-16);
make.top.equalTo(self);
make.bottom.equalTo(self);
}];
//
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-13 19:07:59 +08:00
make.left.equalTo(self.containerView).offset(32);
make.top.equalTo(self.containerView).offset(KB_NAV_TOTAL_HEIGHT + 20);
2025-11-13 16:23:46 +08:00
}];
//
[self.yellowStarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.titleLabel.mas_centerY).offset(6);
make.left.equalTo(self.containerView).offset(6);
2025-11-13 19:07:59 +08:00
make.width.height.mas_equalTo(18);
}];
[self.yellowStarView2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.titleLabel.mas_top).offset(6);
make.left.equalTo(self.titleLabel.mas_right).offset(6);
2025-11-13 16:23:46 +08:00
make.width.height.mas_equalTo(16);
}];
// 绿
[self.greenStarView mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-13 19:07:59 +08:00
make.top.equalTo(self.yellowStarView2).offset(0);
make.left.equalTo(self.yellowStarView2.mas_right).offset(62);
make.width.height.mas_equalTo(20);
}];
[self.greenStarView2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.greenStarView.mas_bottom).offset(10);
make.right.equalTo(self.containerView).offset(-18);
make.width.height.mas_equalTo(14);
}];
[self.greenStarView3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.greenStarView2.mas_bottom).offset(20);
make.right.equalTo(self.containerView).offset(0);
2025-11-13 16:23:46 +08:00
make.width.height.mas_equalTo(14);
}];
//
[self.bigCoinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.containerView);
make.left.right.equalTo(self.containerView);
make.height.mas_equalTo(KBFit(238));
}];
//
[self.infoCard mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.containerView);
make.bottom.equalTo(self.containerView);
make.height.mas_equalTo(KBFit(140));
}];
[self.myPointsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.infoCard).offset(16);
2025-11-13 19:07:59 +08:00
make.bottom.equalTo(self.smallCoinView.mas_top).offset(-16);
2025-11-13 16:23:46 +08:00
}];
[self.smallCoinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.infoCard).offset(16);
2025-11-13 19:07:59 +08:00
make.centerY.equalTo(self.amountLabel);
make.width.height.mas_equalTo(38);
2025-11-13 16:23:46 +08:00
}];
[self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.smallCoinView.mas_right).offset(10);
2025-11-13 19:07:59 +08:00
make.centerY.equalTo(self.rechargeButton);
2025-11-13 16:23:46 +08:00
}];
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-13 19:07:59 +08:00
make.bottom.equalTo(self.infoCard).offset(-32);
make.right.equalTo(self.infoCard).offset(-15);
make.width.mas_equalTo(114);
make.height.mas_equalTo(42);
2025-11-13 16:23:46 +08:00
}];
2025-11-13 14:11:44 +08:00
}
return self;
2025-11-09 13:56:13 +08:00
}
2025-11-13 16:23:46 +08:00
- (void)layoutSubviews {
[super layoutSubviews];
//
// self.containerView.layer.cornerRadius = 16.0;
// self.containerView.layer.masksToBounds = YES;
//
// self.infoCard.layer.cornerRadius = 16.0;
// self.infoCard.layer.masksToBounds = YES;
//
// // 绿
// //
// NSMutableArray<CALayer *> *remove = [NSMutableArray array];
// for (CALayer *l in self.infoCard.layer.sublayers) {
// if ([l isKindOfClass:[CAGradientLayer class]]) { [remove addObject:l]; }
// }
// for (CALayer *l in remove) { [l removeFromSuperlayer]; }
//
// CAGradientLayer *g = [CAGradientLayer layer];
// g.colors = @[(__bridge id)[UIColor colorWithHex:0xF4FFFE].CGColor,
// (__bridge id)[UIColor colorWithHex:0xE8FFF6].CGColor];
// g.startPoint = CGPointMake(0, 0.5);
// g.endPoint = CGPointMake(1, 0.5);
// g.frame = self.infoCard.bounds;
// [self.infoCard.layer insertSublayer:g atIndex:0];
}
#pragma mark - Public
- (void)updatePoints:(NSString *)points {
if (points.length == 0) { points = @"0"; }
self.amountLabel.text = points;
}
#pragma mark - Actions
- (void)onRechargeTappedAction {
2025-11-17 14:53:23 +08:00
// if (self.onRechargeTapped) { self.onRechargeTapped(); }
KBJfPay *vc = [[KBJfPay alloc] init];
[KB_CURRENT_NAV pushViewController:vc animated:true];
2025-11-13 16:23:46 +08:00
}
#pragma mark - Lazy UI
- (UIView *)containerView {
if (!_containerView) {
_containerView = [UIView new];
// _containerView.backgroundColor = [UIColor whiteColor];
}
return _containerView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.numberOfLines = 0;
_titleLabel.text = @"Points\nMall"; //
_titleLabel.font = [UIFont systemFontOfSize:30 weight:UIFontWeightBold];
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
}
return _titleLabel;
}
- (UIImageView *)yellowStarView {
if (!_yellowStarView) {
_yellowStarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_yellowxx_icon"]];
_yellowStarView.contentMode = UIViewContentModeScaleAspectFit;
}
return _yellowStarView;
}
2025-11-13 19:07:59 +08:00
- (UIImageView *)yellowStarView2 {
if (!_yellowStarView2) {
_yellowStarView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_yellowxx_icon"]];
_yellowStarView2.contentMode = UIViewContentModeScaleAspectFit;
}
return _yellowStarView2;
}
2025-11-13 16:23:46 +08:00
- (UIImageView *)greenStarView {
if (!_greenStarView) {
_greenStarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_greenxx_icon"]];
_greenStarView.contentMode = UIViewContentModeScaleAspectFit;
}
return _greenStarView;
}
2025-11-13 19:07:59 +08:00
- (UIImageView *)greenStarView2 {
if (!_greenStarView2) {
_greenStarView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_greenxx_icon"]];
_greenStarView2.contentMode = UIViewContentModeScaleAspectFit;
}
return _greenStarView2;
}
- (UIImageView *)greenStarView3 {
if (!_greenStarView3) {
_greenStarView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_greenxx_icon"]];
_greenStarView3.contentMode = UIViewContentModeScaleAspectFit;
}
return _greenStarView3;
}
2025-11-13 16:23:46 +08:00
- (UIImageView *)bigCoinView {
if (!_bigCoinView) {
_bigCoinView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_headbigBg_icon"]];
_bigCoinView.contentMode = UIViewContentModeScaleAspectFit;
}
return _bigCoinView;
}
- (UIView *)infoCard {
if (!_infoCard) {
_infoCard = [UIView new];
}
return _infoCard;
}
- (UILabel *)myPointsLabel {
if (!_myPointsLabel) {
_myPointsLabel = [UILabel new];
_myPointsLabel.text = @"My Points";
2025-11-13 19:07:59 +08:00
_myPointsLabel.textColor = [UIColor colorWithHex:KBBlackValue];
_myPointsLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
2025-11-13 16:23:46 +08:00
}
return _myPointsLabel;
}
- (UIImageView *)smallCoinView {
if (!_smallCoinView) {
_smallCoinView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_jb_icon"]];
_smallCoinView.contentMode = UIViewContentModeScaleAspectFit;
}
return _smallCoinView;
}
- (UILabel *)amountLabel {
if (!_amountLabel) {
_amountLabel = [UILabel new];
2025-11-13 19:07:59 +08:00
_amountLabel.text = @"88.00";
2025-11-13 16:23:46 +08:00
_amountLabel.textColor = [UIColor colorWithHex:KBColorValue];
2025-11-13 19:07:59 +08:00
_amountLabel.font = [UIFont systemFontOfSize:40 weight:UIFontWeightBold];
2025-11-13 16:23:46 +08:00
_amountLabel.adjustsFontSizeToFitWidth = YES;
2025-11-13 19:07:59 +08:00
// _amountLabel.minimumScaleFactor = 0.7;
2025-11-13 16:23:46 +08:00
}
return _amountLabel;
}
- (UIButton *)rechargeButton {
if (!_rechargeButton) {
_rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rechargeButton setTitle:@"Recharge" forState:UIControlStateNormal];
2025-11-13 19:07:59 +08:00
[_rechargeButton setTitleColor:[UIColor colorWithHex:KBBlackValue] forState:UIControlStateNormal];
_rechargeButton.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
2025-11-13 16:23:46 +08:00
UIImage *bg = [UIImage imageNamed:@"recharge_btn_bg"];
2025-11-13 19:07:59 +08:00
[_rechargeButton setBackgroundImage:bg forState:UIControlStateNormal];
//
// //
// UIImage *bg = [UIImage imageNamed:@"recharge_btn_bg"];
// if (bg) {
// CGFloat cap = 20; //
// bg = [bg resizableImageWithCapInsets:UIEdgeInsetsMake(cap, cap, cap, cap) resizingMode:UIImageResizingModeStretch];
// [_rechargeButton setBackgroundImage:bg forState:UIControlStateNormal];
// } else {
// // 绿
// UIImage *fallback = [UIImage kb_gradientImageWithColors:@[[UIColor colorWithHex:0xA6F6E9], [UIColor colorWithHex:0xD6FFF4]]
// size:CGSizeMake(120, 40)
// direction:KBGradientDirectionLeftToRight];
// [_rechargeButton setBackgroundImage:fallback forState:UIControlStateNormal];
// }
//
// _rechargeButton.layer.cornerRadius = 20;
// _rechargeButton.layer.masksToBounds = YES;
2025-11-13 16:23:46 +08:00
[_rechargeButton addTarget:self action:@selector(onRechargeTappedAction) forControlEvents:UIControlEventTouchUpInside];
}
return _rechargeButton;
}
2025-11-09 13:56:13 +08:00
@end