添加按钮文字预览提示

This commit is contained in:
2025-11-20 21:11:27 +08:00
parent 6bdd111a3a
commit faa05e2a10
6 changed files with 168 additions and 3 deletions

View File

@@ -0,0 +1,56 @@
//
// KBKeyPreviewView.m
// CustomKeyboard
//
#import "KBKeyPreviewView.h"
#import "KBKey.h"
@interface KBKeyPreviewView ()
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIImageView *iconView;
@end
@implementation KBKeyPreviewView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor colorWithWhite:1 alpha:1.0];
self.layer.cornerRadius = 8.0;
self.layer.masksToBounds = YES;
self.layer.borderWidth = 0.5;
self.layer.borderColor = [UIColor colorWithWhite:0 alpha:0.15].CGColor;
self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.3].CGColor;
self.layer.shadowOpacity = 0.6;
self.layer.shadowOffset = CGSizeMake(0, 2);
self.layer.shadowRadius = 4.0;
// _iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
// _iconView.contentMode = UIViewContentModeScaleAspectFit;
// _iconView.translatesAutoresizingMaskIntoConstraints = NO;
// [self addSubview:_iconView];
_label = [[UILabel alloc] initWithFrame:CGRectZero];
_label.font = [UIFont systemFontOfSize:28 weight:UIFontWeightSemibold];
_label.textAlignment = NSTextAlignmentCenter;
_label.textColor = [UIColor blackColor];
_label.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_label];
// 使
[NSLayoutConstraint activateConstraints:@[
[_label.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:4],
[_label.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-4],
[_label.topAnchor constraintEqualToAnchor:self.topAnchor constant:2],
[_label.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-2],
]];
}
return self;
}
- (void)configureWithKey:(KBKey *)key icon:(UIImage *)icon {
NSString *text = key.output.length > 0 ? key.output : key.title;
self.label.text = text;
}
@end