This commit is contained in:
2025-11-18 20:53:47 +08:00
parent 254e65906a
commit 3dcc4932c3
109 changed files with 1432 additions and 84 deletions

View File

@@ -7,6 +7,10 @@
#import "KBKey.h"
#import "KBSkinManager.h"
@interface KBKeyButton ()
@property (nonatomic, strong) UIImageView *iconView;
@end
@implementation KBKeyButton
- (instancetype)initWithFrame:(CGRect)frame {
@@ -29,6 +33,34 @@
self.layer.shadowOffset = CGSizeMake(0, 1);
self.layer.shadowRadius = 1.5;
[self refreshStateAppearance];
//
if (!self.iconView) {
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectZero];
//
iv.contentMode = UIViewContentModeScaleAspectFill;
iv.clipsToBounds = YES;
iv.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:iv];
//
[NSLayoutConstraint activateConstraints:@[
[iv.topAnchor constraintEqualToAnchor:self.topAnchor],
[iv.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
[iv.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[iv.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
]];
self.iconView = iv;
//
self.titleEdgeInsets = UIEdgeInsetsZero;
[self bringSubviewToFront:self.titleLabel];
}
}
- (void)setKey:(KBKey *)key {
_key = key;
//
[self applyThemeForCurrentKey];
}
- (void)setHighlighted:(BOOL)highlighted {
@@ -56,4 +88,19 @@
}
}
- (void)applyThemeForCurrentKey {
//
NSString *identifier = self.key.identifier;
BOOL hideText = [[KBSkinManager shared] shouldHideKeyTextForIdentifier:identifier];
self.titleLabel.hidden = hideText;
//
// - identifier: letter_q
// - caseVariant: 0/1/2 => //
NSInteger variant = (NSInteger)self.key.caseVariant;
UIImage *iconImg = [[KBSkinManager shared] iconImageForKeyIdentifier:identifier caseVariant:variant];
self.iconView.image = iconImg;
self.iconView.hidden = (iconImg == nil);
}
@end