Files
keyboard/keyBoard/Class/Pay/V/KBVipPayHeaderView.m

154 lines
5.7 KiB
Mathematica
Raw Normal View History

2025-11-14 19:48:15 +08:00
//
// KBVipPayHeaderView.m
// keyBoard
//
// 使 Masonry 5
//
#import "KBVipPayHeaderView.h"
@interface KBVipPayHeaderView ()
// 便 KB_NAV_TOTAL_HEIGHT
@property (nonatomic, strong) UIView *containerView;
// pay_vip_icon
2026-02-04 12:33:01 +08:00
//@property (nonatomic, strong) UIImageView *vipImageView;
//@property (nonatomic, strong) UIImageView *wanImageView;
//@property (nonatomic, strong) UILabel *titleLabel;
//@property (nonatomic, strong) UILabel *desLabel;
2025-11-14 23:09:04 +08:00
2025-11-14 19:48:15 +08:00
//
@property (nonatomic, strong) UIImageView *aiImageView;
@property (nonatomic, strong) UIImageView *keyboardImageView;
@property (nonatomic, strong) UIImageView *chatImageView;
@property (nonatomic, strong) UIImageView *emotionImageView;
@end
@implementation KBVipPayHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
2026-02-04 14:59:02 +08:00
self.backgroundColor = [UIColor colorWithHex:0xF6F7FB];
2025-11-14 19:48:15 +08:00
[self addSubview:self.containerView];
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
// 2.
UIView *g1 = [self gridItemWithImageView:self.aiImageView];
UIView *g2 = [self gridItemWithImageView:self.keyboardImageView];
UIView *g3 = [self gridItemWithImageView:self.chatImageView];
UIView *g4 = [self gridItemWithImageView:self.emotionImageView];
[self.containerView addSubview:g1];
[self.containerView addSubview:g2];
[self.containerView addSubview:g3];
[self.containerView addSubview:g4];
2025-11-14 23:09:04 +08:00
CGFloat spacing = 16;
2025-11-14 19:48:15 +08:00
[g1 mas_makeConstraints:^(MASConstraintMaker *make) {
2026-02-04 12:33:01 +08:00
make.left.equalTo(self.containerView).inset(KBFit(27));
2026-02-04 14:59:02 +08:00
make.top.equalTo(self.containerView).offset(25);
2025-11-15 00:33:29 +08:00
make.height.mas_equalTo(((KBFit(122))));
2025-11-14 19:48:15 +08:00
}];
[g2 mas_makeConstraints:^(MASConstraintMaker *make) {
2026-02-04 12:33:01 +08:00
make.right.equalTo(self.containerView).inset(KBFit(27));
2025-11-14 19:48:15 +08:00
make.top.equalTo(g1);
make.height.equalTo(g1);
make.left.equalTo(g1.mas_right).offset(spacing);
make.width.equalTo(g1);
}];
[g3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(g1);
make.top.equalTo(g1.mas_bottom).offset(spacing);
make.height.equalTo(g1);
make.width.equalTo(g1);
}];
[g4 mas_makeConstraints:^(MASConstraintMaker *make) {
2026-02-04 12:33:01 +08:00
make.right.equalTo(g2);
2025-11-14 19:48:15 +08:00
make.top.equalTo(g3);
make.left.equalTo(g3.mas_right).offset(spacing);
make.height.equalTo(g1);
make.width.equalTo(g1);
2025-11-15 00:33:29 +08:00
// header
make.bottom.equalTo(self.containerView).offset(-12);
2025-11-14 19:48:15 +08:00
}];
}
return self;
}
2025-11-15 00:33:29 +08:00
// header AutoLayout
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
CGFloat targetWidth = layoutAttributes.size.width > 0 ? layoutAttributes.size.width : KB_SCREEN_WIDTH;
// 便
self.bounds = CGRectMake(0, 0, targetWidth, self.bounds.size.height);
[self setNeedsLayout];
[self layoutIfNeeded];
CGSize fit = [self systemLayoutSizeFittingSize:CGSizeMake(targetWidth, UILayoutFittingCompressedSize.height)
withHorizontalFittingPriority:UILayoutPriorityRequired
verticalFittingPriority:UILayoutPriorityFittingSizeLevel];
CGRect f = layoutAttributes.frame;
f.size.height = ceil(fit.height);
layoutAttributes.frame = f;
return layoutAttributes;
}
2025-11-14 19:48:15 +08:00
#pragma mark - Helpers
- (UIView *)gridItemWithImageView:(UIImageView *)iv {
//
UIView *v = [UIView new];
2025-11-14 23:09:04 +08:00
// v.backgroundColor = [UIColor colorWithWhite:0.97 alpha:1.0];
// v.layer.cornerRadius = 12;
// v.layer.masksToBounds = YES;
2025-11-14 19:48:15 +08:00
[v addSubview:iv];
2025-11-15 00:33:29 +08:00
iv.contentMode = UIViewContentModeScaleAspectFit;
2025-11-14 19:48:15 +08:00
[iv mas_makeConstraints:^(MASConstraintMaker *make) {
2025-11-14 23:09:04 +08:00
// make.center.equalTo(v);
// make.width.height.mas_equalTo(40);
make.edges.equalTo(v);
2025-11-14 19:48:15 +08:00
}];
return v;
}
#pragma mark - Lazy
- (UIView *)containerView {
if (!_containerView) {
_containerView = [UIView new];
_containerView.backgroundColor = [UIColor clearColor];
}
return _containerView;
}
2025-11-14 23:09:04 +08:00
2025-11-14 19:48:15 +08:00
- (UIImageView *)aiImageView {
if (!_aiImageView) {
_aiImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pay_ai_icon"]];
_aiImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _aiImageView;
}
- (UIImageView *)keyboardImageView {
if (!_keyboardImageView) {
_keyboardImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pay_keyboard_icon"]];
_keyboardImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _keyboardImageView;
}
- (UIImageView *)chatImageView {
if (!_chatImageView) {
_chatImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pay_chat_icon"]];
_chatImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _chatImageView;
}
- (UIImageView *)emotionImageView {
if (!_emotionImageView) {
_emotionImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pay_emotion_icon"]];
_emotionImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _emotionImageView;
}
2025-11-14 23:09:04 +08:00
2025-11-14 19:48:15 +08:00
@end