处理键盘图片和自定义文字同时存在的bug
This commit is contained in:
@@ -59,8 +59,6 @@
|
||||
|
||||
- (void)setKey:(KBKey *)key {
|
||||
_key = key;
|
||||
// 每次切换按键模型时,根据皮肤刷新一次图标和文字显隐
|
||||
[self applyThemeForCurrentKey];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted {
|
||||
@@ -89,18 +87,31 @@
|
||||
}
|
||||
|
||||
- (void)applyThemeForCurrentKey {
|
||||
// 依据皮肤决定是否显示文字
|
||||
NSString *identifier = self.key.identifier;
|
||||
BOOL hideText = [[KBSkinManager shared] shouldHideKeyTextForIdentifier:identifier];
|
||||
self.titleLabel.hidden = hideText;
|
||||
|
||||
// 根据皮肤映射加载图标(若有),支持大小写变体:
|
||||
// - identifier: 逻辑按键标识(如 letter_q)
|
||||
// - caseVariant: 0/1/2 => 无变体/小写/大写
|
||||
NSString *identifier = self.key.identifier;
|
||||
NSInteger variant = (NSInteger)self.key.caseVariant;
|
||||
UIImage *iconImg = [[KBSkinManager shared] iconImageForKeyIdentifier:identifier caseVariant:variant];
|
||||
|
||||
// 设置整块按键背景图(若有)
|
||||
self.iconView.image = iconImg;
|
||||
self.iconView.hidden = (iconImg == nil);
|
||||
|
||||
BOOL hasIcon = (iconImg != nil);
|
||||
|
||||
if (hasIcon) {
|
||||
// 有图标:仅显示图片,完全隐藏文字
|
||||
[self setTitle:@"" forState:UIControlStateNormal];
|
||||
[self setTitle:@"" forState:UIControlStateHighlighted];
|
||||
[self setTitle:@"" forState:UIControlStateSelected];
|
||||
self.titleLabel.hidden = YES;
|
||||
} else {
|
||||
// 无图标:按键标题正常显示(使用 key.title),并根据 hidden_keys 决定要不要隐藏
|
||||
[self setTitle:self.key.title forState:UIControlStateNormal];
|
||||
BOOL hideTextBySkin = [[KBSkinManager shared] shouldHideKeyTextForIdentifier:identifier];
|
||||
self.titleLabel.hidden = hideTextBySkin;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -298,6 +298,8 @@
|
||||
KBKeyButton *btn = [[KBKeyButton alloc] init];
|
||||
btn.key = key;
|
||||
[btn setTitle:key.title forState:UIControlStateNormal];
|
||||
// 在设置完标题后,按当前皮肤应用图标与文字显隐
|
||||
[btn applyThemeForCurrentKey];
|
||||
[btn addTarget:self action:@selector(onKeyTapped:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[row addSubview:btn];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user