This commit is contained in:
2025-10-28 20:11:40 +08:00
parent 935284388c
commit 13facba33a
3 changed files with 29 additions and 1 deletions

View File

@@ -14,4 +14,7 @@
/// 配置基础样式(背景、圆角等)。创建按钮时调用。
- (void)applyDefaultStyle;
/// 根据选中/高亮等状态刷新外观
- (void)refreshStateAppearance;
@end

View File

@@ -26,11 +26,31 @@
self.layer.shadowOpacity = 1.0;
self.layer.shadowOffset = CGSizeMake(0, 1);
self.layer.shadowRadius = 1.5;
[self refreshStateAppearance];
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
self.alpha = highlighted ? 0.7 : 1.0; //
//
if (self.isSelected) {
self.alpha = 1.0;
} else {
self.alpha = highlighted ? 0.7 : 1.0;
}
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
[self refreshStateAppearance];
}
- (void)refreshStateAppearance {
// Shift/CapsLock
if (self.isSelected) {
self.backgroundColor = [UIColor colorWithWhite:0.85 alpha:1.0];
} else {
self.backgroundColor = [UIColor whiteColor];
}
}
@end

View File

@@ -198,6 +198,11 @@
[btn addTarget:self action:@selector(onKeyTapped:) forControlEvents:UIControlEventTouchUpInside];
[row addSubview:btn];
// Shift
if (key.type == KBKeyTypeShift) {
btn.selected = self.shiftOn;
}
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(row);
if (previous) {