This commit is contained in:
2026-01-15 19:14:34 +08:00
parent 8f4deaac4e
commit b5da9f35a5
4 changed files with 31 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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