From 4108aed4e0d2b00249c963acdd45e218418966cb Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 19 Nov 2025 16:13:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=94=AE=E7=9B=98=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=92=8C=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=AD=98=E5=9C=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/View/KBKeyButton.m | 25 ++++++++++++++++++------- CustomKeyboard/View/KBKeyboardView.m | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CustomKeyboard/View/KBKeyButton.m b/CustomKeyboard/View/KBKeyButton.m index ba827da..a0501dd 100644 --- a/CustomKeyboard/View/KBKeyButton.m +++ b/CustomKeyboard/View/KBKeyButton.m @@ -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 diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index 0d03707..783980b 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -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];