1
This commit is contained in:
16
keyBoard/Class/Common/V/KBMoneyBtn.h
Normal file
16
keyBoard/Class/Common/V/KBMoneyBtn.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// KBMoneyBtn.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/17.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBMoneyBtn : UIButton
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
68
keyBoard/Class/Common/V/KBMoneyBtn.m
Normal file
68
keyBoard/Class/Common/V/KBMoneyBtn.m
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// KBMoneyBtn.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/11/17.
|
||||
//
|
||||
|
||||
#import "KBMoneyBtn.h"
|
||||
#import "UIColor+Extension.h"
|
||||
|
||||
@implementation KBMoneyBtn
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self kb_setupUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self kb_setupUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)kb_setupUI {
|
||||
// 背景:#EDFFFD,透明度 0.72
|
||||
// self.backgroundColor = [UIColor colorWithHex:0xEDFFFD alpha:0.72];
|
||||
self.backgroundColor = [UIColor colorWithHex:0xEDFFFD];
|
||||
|
||||
// 文字样式:颜色 0x02BEAC,数字展示用稍大一点的字号
|
||||
[self setTitleColor:[UIColor colorWithHex:0x02BEAC] forState:UIControlStateNormal];
|
||||
self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
|
||||
// 左侧金币图标
|
||||
UIImage *icon = [UIImage imageNamed:@"shop_jbsmall_icon"];
|
||||
if (icon) {
|
||||
[self setImage:icon forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
// 内容靠左,预留左右内边距
|
||||
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
self.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
|
||||
|
||||
// 图片与文字间距 15:通过 imageEdgeInsets / titleEdgeInsets 调整
|
||||
CGFloat spacing = 5.0;
|
||||
self.imageEdgeInsets = UIEdgeInsetsMake(0, -spacing / 2.0, 0, spacing / 2.0);
|
||||
self.titleEdgeInsets = UIEdgeInsetsMake(0, spacing / 2.0, 0, -spacing / 2.0);
|
||||
|
||||
// 高亮时不要变暗太多
|
||||
self.adjustsImageWhenHighlighted = YES;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
CGFloat h = CGRectGetHeight(self.bounds);
|
||||
if (h <= 0) { return; }
|
||||
|
||||
// 胶囊圆角
|
||||
self.layer.cornerRadius = h / 2.0;
|
||||
self.clipsToBounds = YES;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user