Files
keyboard/CustomKeyboard/View/KBKeyButton.m

60 lines
1.7 KiB
Mathematica
Raw Normal View History

2025-10-28 10:18:10 +08:00
//
// KBKeyButton.m
// CustomKeyboard
//
#import "KBKeyButton.h"
#import "KBKey.h"
2025-11-04 21:01:46 +08:00
#import "KBSkinManager.h"
2025-10-28 10:18:10 +08:00
@implementation KBKeyButton
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self applyDefaultStyle];
}
return self;
}
- (void)applyDefaultStyle {
2025-11-04 21:01:46 +08:00
self.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
KBSkinTheme *t = [KBSkinManager shared].current;
[self setTitleColor:t.keyTextColor forState:UIControlStateNormal];
[self setTitleColor:t.keyTextColor forState:UIControlStateHighlighted];
self.backgroundColor = t.keyBackground;
2025-10-28 10:18:10 +08:00
self.layer.cornerRadius = 6.0; //
self.layer.masksToBounds = NO;
self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor; //
self.layer.shadowOpacity = 1.0;
self.layer.shadowOffset = CGSizeMake(0, 1);
self.layer.shadowRadius = 1.5;
2025-10-28 20:11:40 +08:00
[self refreshStateAppearance];
2025-10-28 10:18:10 +08:00
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
2025-10-28 20:11:40 +08:00
//
if (self.isSelected) {
self.alpha = 1.0;
} else {
2025-10-28 21:27:01 +08:00
self.alpha = highlighted ? 0.2 : 1.0;
2025-10-28 20:11:40 +08:00
}
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
[self refreshStateAppearance];
}
- (void)refreshStateAppearance {
// Shift/CapsLock
2025-11-04 21:01:46 +08:00
KBSkinTheme *t = [KBSkinManager shared].current;
2025-10-28 20:11:40 +08:00
if (self.isSelected) {
2025-11-04 21:01:46 +08:00
self.backgroundColor = t.keyHighlightBackground ?: t.keyBackground;
2025-10-28 20:11:40 +08:00
} else {
2025-11-04 21:01:46 +08:00
self.backgroundColor = t.keyBackground;
2025-10-28 20:11:40 +08:00
}
2025-10-28 10:18:10 +08:00
}
@end