From b5da9f35a542de05e0bb017ebcc301a81d9f7f55 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 15 Jan 2026 19:14:34 +0800 Subject: [PATCH] 4 --- CustomKeyboard/View/KBChatMessageCell.m | 13 +++++++++++-- CustomKeyboard/View/KBChatPanelView.m | 4 +++- keyBoard/Class/Categories/UIColor+Extension.h | 2 ++ keyBoard/Class/Categories/UIColor+Extension.m | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CustomKeyboard/View/KBChatMessageCell.m b/CustomKeyboard/View/KBChatMessageCell.m index 5b8dde7..c55d37a 100644 --- a/CustomKeyboard/View/KBChatMessageCell.m +++ b/CustomKeyboard/View/KBChatMessageCell.m @@ -38,7 +38,13 @@ BOOL outgoing = message.outgoing; BOOL audioMessage = (!outgoing && message.audioFilePath.length > 0); UIColor *bubbleColor = outgoing ? [UIColor colorWithHex:0x02BEAC] : [UIColor colorWithWhite:1 alpha:0.95]; - UIColor *textColor = outgoing ? [UIColor whiteColor] : [UIColor colorWithHex:0x1B1F1A]; + UIColor *incomingTextColor = + [UIColor kb_dynamicColorWithLightColor:[UIColor colorWithHex:0x1B1F1A] + darkColor:[UIColor whiteColor]]; + UIColor *textColor = outgoing ? [UIColor whiteColor] : incomingTextColor; + UIColor *nameColor = + [UIColor kb_dynamicColorWithLightColor:[UIColor colorWithHex:0x6B6F7A] + darkColor:[UIColor colorWithHex:0xC7CBD4]]; self.bubbleView.backgroundColor = bubbleColor; self.messageLabel.textColor = textColor; @@ -59,6 +65,7 @@ self.avatarView.backgroundColor = avatarImage ? [UIColor clearColor] : [UIColor colorWithWhite:0.9 alpha:1.0]; self.nameLabel.hidden = outgoing; + self.nameLabel.textColor = nameColor; self.nameLabel.text = (message.displayName.length > 0) ? message.displayName : KBLocalized(@"AI助手"); @@ -129,7 +136,9 @@ _avatarView.layer.cornerRadius = 14; _avatarView.layer.masksToBounds = YES; _avatarView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0]; - _avatarView.tintColor = [UIColor colorWithHex:0xB9BDC8]; + _avatarView.tintColor = + [UIColor kb_dynamicColorWithLightColor:[UIColor colorWithHex:0xB9BDC8] + darkColor:[UIColor colorWithHex:0x6B6F7A]]; } return _avatarView; } diff --git a/CustomKeyboard/View/KBChatPanelView.m b/CustomKeyboard/View/KBChatPanelView.m index c2eb651..05e92e3 100644 --- a/CustomKeyboard/View/KBChatPanelView.m +++ b/CustomKeyboard/View/KBChatPanelView.m @@ -144,7 +144,9 @@ if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; - _titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A]; + _titleLabel.textColor = + [UIColor kb_dynamicColorWithLightColor:[UIColor colorWithHex:0x1B1F1A] + darkColor:[UIColor whiteColor]]; _titleLabel.text = KBLocalized(@"AI对话"); } return _titleLabel; diff --git a/keyBoard/Class/Categories/UIColor+Extension.h b/keyBoard/Class/Categories/UIColor+Extension.h index 5beb164..170bb4d 100644 --- a/keyBoard/Class/Categories/UIColor+Extension.h +++ b/keyBoard/Class/Categories/UIColor+Extension.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN @interface UIColor (Extension) + (UIColor *)colorWithHex:(int)hexValue; + (nullable UIColor *)colorWithHexString:(NSString *)hexString; ++ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor + darkColor:(UIColor *)darkColor; @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Categories/UIColor+Extension.m b/keyBoard/Class/Categories/UIColor+Extension.m index 2a719ae..04e5d2d 100644 --- a/keyBoard/Class/Categories/UIColor+Extension.m +++ b/keyBoard/Class/Categories/UIColor+Extension.m @@ -41,4 +41,19 @@ int rgb = (int)(value & 0xFFFFFF); return [UIColor colorWithHex:rgb alpha:alpha]; } + ++ (UIColor *)kb_dynamicColorWithLightColor:(UIColor *)lightColor + darkColor:(UIColor *)darkColor { + UIColor *light = lightColor ?: [UIColor blackColor]; + UIColor *dark = darkColor ?: light; + if (@available(iOS 13.0, *)) { + return [UIColor colorWithDynamicProvider:^UIColor *_Nonnull(UITraitCollection *_Nonnull traitCollection) { + if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { + return dark; + } + return light; + }]; + } + return light; +} @end