2025-11-06 13:18:27 +08:00
|
|
|
|
//
|
|
|
|
|
|
// HomeHeadView.m
|
|
|
|
|
|
// keyBoard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Mac on 2025/11/6.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "HomeHeadView.h"
|
2025-11-07 14:21:03 +08:00
|
|
|
|
#import "UIImage+KBColor.h"
|
|
|
|
|
|
#import "KBTopImageButton.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface HomeHeadView()
|
2025-11-07 20:58:14 +08:00
|
|
|
|
@property (nonatomic, strong) UIImageView *loveKeyImageView;
|
|
|
|
|
|
|
2025-11-07 14:21:03 +08:00
|
|
|
|
// 顶部会员卡图片
|
|
|
|
|
|
@property (nonatomic, strong) UIImageView *vipImageView;
|
|
|
|
|
|
// 主/副标题
|
|
|
|
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
|
|
|
|
@property (nonatomic, strong) UILabel *subTitleLabel;
|
|
|
|
|
|
// 中部四个功能按钮容器
|
|
|
|
|
|
@property (nonatomic, strong) UIView *featuresContainer;
|
|
|
|
|
|
@property (nonatomic, strong) NSArray<KBTopImageButton *> *featureButtons;
|
|
|
|
|
|
// 底部购买按钮
|
|
|
|
|
|
@property (nonatomic, strong) UIButton *buyButton;
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
2025-11-06 13:18:27 +08:00
|
|
|
|
|
|
|
|
|
|
@implementation HomeHeadView
|
|
|
|
|
|
|
2025-11-06 14:02:22 +08:00
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame{
|
|
|
|
|
|
if (self = [super initWithFrame:frame]) {
|
2025-11-06 21:38:58 +08:00
|
|
|
|
self.backgroundColor = [UIColor clearColor];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
[self setupViews];
|
|
|
|
|
|
[self setupConstraints];
|
|
|
|
|
|
[self defaultData];
|
2025-11-06 14:02:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
return self;
|
2025-11-06 13:18:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-07 14:21:03 +08:00
|
|
|
|
#pragma mark - Layout
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
|
|
[super layoutSubviews];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - UI
|
|
|
|
|
|
- (void)setupViews {
|
2025-11-07 20:58:14 +08:00
|
|
|
|
// [self addSubview:self.loveKeyImageView];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
[self addSubview:self.vipImageView];
|
|
|
|
|
|
[self addSubview:self.titleLabel];
|
|
|
|
|
|
[self addSubview:self.subTitleLabel];
|
|
|
|
|
|
[self addSubview:self.featuresContainer];
|
|
|
|
|
|
[self addSubview:self.buyButton];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setupConstraints {
|
|
|
|
|
|
// 顶部图
|
|
|
|
|
|
[self.vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.top.equalTo(self.mas_top).offset(2);
|
|
|
|
|
|
make.centerX.equalTo(self);
|
|
|
|
|
|
make.width.mas_equalTo(217);
|
|
|
|
|
|
make.height.mas_equalTo(166);
|
|
|
|
|
|
}];
|
2025-11-07 20:58:14 +08:00
|
|
|
|
|
|
|
|
|
|
// [self.loveKeyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
// make.top.equalTo(self.vipImageView.mas_centerY).offset(0);
|
|
|
|
|
|
// make.right.equalTo(self).offset(-16);
|
|
|
|
|
|
// make.width.mas_equalTo(335);
|
|
|
|
|
|
// make.height.mas_equalTo(117);
|
|
|
|
|
|
// }];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
|
|
|
|
|
|
// 主标题
|
|
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.top.equalTo(self.vipImageView.mas_bottom).offset(28);
|
|
|
|
|
|
make.centerX.equalTo(self);
|
|
|
|
|
|
make.left.greaterThanOrEqualTo(self.mas_left).offset(16);
|
|
|
|
|
|
make.right.lessThanOrEqualTo(self.mas_right).offset(-16);
|
|
|
|
|
|
make.height.mas_equalTo(26);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 副标题
|
|
|
|
|
|
[self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.top.equalTo(self.titleLabel.mas_bottom).offset(3);
|
|
|
|
|
|
make.centerX.equalTo(self.titleLabel);
|
|
|
|
|
|
make.left.greaterThanOrEqualTo(self.mas_left).offset(16);
|
|
|
|
|
|
make.right.lessThanOrEqualTo(self.mas_right).offset(-16);
|
|
|
|
|
|
make.height.mas_equalTo(20);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 功能按钮容器
|
|
|
|
|
|
[self.featuresContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.top.equalTo(self.subTitleLabel.mas_bottom).offset(16);
|
|
|
|
|
|
make.left.equalTo(self.mas_left).offset(16);
|
|
|
|
|
|
make.right.equalTo(self.mas_right).offset(-16);
|
2025-11-07 20:58:14 +08:00
|
|
|
|
make.height.mas_equalTo(80);
|
2025-11-07 14:21:03 +08:00
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 四个按钮等宽分布
|
|
|
|
|
|
KBTopImageButton *b0 = self.featureButtons[0];
|
|
|
|
|
|
KBTopImageButton *b1 = self.featureButtons[1];
|
|
|
|
|
|
KBTopImageButton *b2 = self.featureButtons[2];
|
|
|
|
|
|
KBTopImageButton *b3 = self.featureButtons[3];
|
|
|
|
|
|
|
|
|
|
|
|
[b0 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.top.bottom.equalTo(self.featuresContainer);
|
|
|
|
|
|
}];
|
|
|
|
|
|
[b1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.equalTo(b0.mas_right);
|
|
|
|
|
|
make.top.bottom.equalTo(b0);
|
|
|
|
|
|
make.width.equalTo(b0);
|
|
|
|
|
|
}];
|
|
|
|
|
|
[b2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.equalTo(b1.mas_right);
|
|
|
|
|
|
make.top.bottom.equalTo(b0);
|
|
|
|
|
|
make.width.equalTo(b0);
|
|
|
|
|
|
}];
|
|
|
|
|
|
[b3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.equalTo(b2.mas_right);
|
|
|
|
|
|
make.top.bottom.right.equalTo(self.featuresContainer);
|
|
|
|
|
|
make.width.equalTo(b0);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 购买按钮
|
|
|
|
|
|
[self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.left.equalTo(self.mas_left).offset(62);
|
|
|
|
|
|
make.right.equalTo(self.mas_right).offset(-62);
|
2025-11-07 19:32:02 +08:00
|
|
|
|
make.bottom.equalTo(self.mas_bottom).offset(0);
|
2025-11-07 14:21:03 +08:00
|
|
|
|
make.height.mas_equalTo(56);
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)defaultData {
|
|
|
|
|
|
// 默认文案(使用英文,便于与示例图一致)
|
|
|
|
|
|
self.titleLabel.text = @"Become A Member Of Love Key";
|
|
|
|
|
|
self.subTitleLabel.text = @"Unlock All Functions";
|
|
|
|
|
|
|
|
|
|
|
|
NSArray *titles = @[@"Wireless Sub-ai\nDialogue",
|
|
|
|
|
|
@"Personalized\nKeyboard",
|
|
|
|
|
|
@"Chat\nPersona",
|
|
|
|
|
|
@"Emotional\nCounseling"];
|
2025-11-07 20:58:14 +08:00
|
|
|
|
NSArray *images = @[[UIImage imageNamed:@"home_ai_icon"],
|
|
|
|
|
|
[UIImage imageNamed:@"home_keyboard_icon"],
|
|
|
|
|
|
[UIImage imageNamed:@"home_chat_icon"],
|
|
|
|
|
|
[UIImage imageNamed:@"home_emotion_icon"]];
|
|
|
|
|
|
[self configureFeatureTitles:titles images:images];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Public
|
|
|
|
|
|
- (void)configureFeatureTitles:(NSArray<NSString *> *)titles images:(NSArray<UIImage *> *)images {
|
|
|
|
|
|
// 设置四个按钮标题与占位图片(如未传图片则生成渐变圆角占位)
|
|
|
|
|
|
NSInteger count = MIN(4, titles.count);
|
|
|
|
|
|
for (NSInteger i = 0; i < 4; i++) {
|
|
|
|
|
|
KBTopImageButton *btn = self.featureButtons[i];
|
|
|
|
|
|
if (i < count) {
|
|
|
|
|
|
btn.textLabel.text = titles[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
UIImage *img = (i < images.count) ? images[i] : nil;
|
|
|
|
|
|
btn.iconView.image = img;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
- (void)onTapBuyAction {
|
|
|
|
|
|
if (self.onTapBuy) { self.onTapBuy(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Lazy
|
|
|
|
|
|
- (UIImageView *)vipImageView{
|
|
|
|
|
|
if (!_vipImageView) {
|
|
|
|
|
|
_vipImageView = [[UIImageView alloc] init];
|
2025-11-07 20:58:14 +08:00
|
|
|
|
_vipImageView.image = [UIImage imageNamed:@"home_topvip_icon"];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
_vipImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _vipImageView;
|
|
|
|
|
|
}
|
2025-11-07 20:58:14 +08:00
|
|
|
|
- (UIImageView *)loveKeyImageView{
|
|
|
|
|
|
if (!_loveKeyImageView) {
|
|
|
|
|
|
_loveKeyImageView = [[UIImageView alloc] init];
|
|
|
|
|
|
_loveKeyImageView.image = [UIImage imageNamed:@"hoem_love_key"];
|
|
|
|
|
|
_loveKeyImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _loveKeyImageView;
|
|
|
|
|
|
}
|
2025-11-07 14:21:03 +08:00
|
|
|
|
|
|
|
|
|
|
- (UILabel *)titleLabel {
|
|
|
|
|
|
if (!_titleLabel) {
|
|
|
|
|
|
_titleLabel = [[UILabel alloc] init];
|
|
|
|
|
|
_titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
|
|
|
|
|
|
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
|
|
|
|
|
|
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _titleLabel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UILabel *)subTitleLabel {
|
|
|
|
|
|
if (!_subTitleLabel) {
|
|
|
|
|
|
_subTitleLabel = [[UILabel alloc] init];
|
|
|
|
|
|
_subTitleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
|
|
|
|
|
|
_subTitleLabel.textColor = self.titleLabel.textColor;
|
|
|
|
|
|
_subTitleLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _subTitleLabel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UIView *)featuresContainer {
|
|
|
|
|
|
if (!_featuresContainer) {
|
|
|
|
|
|
_featuresContainer = [[UIView alloc] init];
|
|
|
|
|
|
// 不显式背景,保留父视图背景;如需调试可设置颜色
|
|
|
|
|
|
// _featuresContainer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.02];
|
|
|
|
|
|
|
|
|
|
|
|
// 创建4个功能按钮(懒加载一并放到数组)
|
|
|
|
|
|
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
|
KBTopImageButton *btn = [[KBTopImageButton alloc] init];
|
2025-11-07 20:58:14 +08:00
|
|
|
|
btn.iconSize = CGSizeMake(54, 44);
|
|
|
|
|
|
btn.spacing = 0;
|
2025-11-07 14:21:03 +08:00
|
|
|
|
[self.featuresContainer addSubview:btn];
|
|
|
|
|
|
[arr addObject:btn];
|
|
|
|
|
|
}
|
|
|
|
|
|
_featureButtons = [arr copy];
|
|
|
|
|
|
}
|
|
|
|
|
|
return _featuresContainer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSArray<KBTopImageButton *> *)featureButtons {
|
|
|
|
|
|
// 只读访问,实际由 featuresContainer 的懒加载创建
|
|
|
|
|
|
if (!_featureButtons) { (void)self.featuresContainer; }
|
|
|
|
|
|
return _featureButtons;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UIButton *)buyButton {
|
|
|
|
|
|
if (!_buyButton) {
|
|
|
|
|
|
_buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
|
[_buyButton setTitle:@"Recharge Now" forState:UIControlStateNormal];
|
|
|
|
|
|
[_buyButton setTitleColor:[UIColor colorWithHex:0x1B1F1A] forState:UIControlStateNormal];
|
|
|
|
|
|
_buyButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
2025-11-07 19:32:02 +08:00
|
|
|
|
[_buyButton setBackgroundImage:[UIImage imageNamed:@"recharge_now_icon"] forState:UIControlStateNormal];
|
2025-11-07 14:21:03 +08:00
|
|
|
|
[_buyButton addTarget:self action:@selector(onTapBuyAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
}
|
|
|
|
|
|
return _buyButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 13:18:27 +08:00
|
|
|
|
@end
|