Skip to content

Commit e743785

Browse files
graycreateclaude
andcommitted
fix: improve tab bar color configuration using SwiftUI modifiers
Fix tab bar colors by using proper SwiftUI approach instead of UIKit appearance APIs: - Use .tint(Color.primary) for selected items (auto-adapts to light/dark mode) - Set appearance.stackedLayoutAppearance for unselected text colors - Remove UITabBar.appearance().tintColor to fix dark mode color reversal Light mode: selected=black, unselected=light gray (78%) Dark mode: selected=white, unselected=dim gray (60%) Text colors now work correctly, icon colors need further fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 31b2270 commit e743785

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

V2er/View/MainPage.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,31 @@ struct MainPage: StateView {
2525
}
2626

2727
init() {
28-
// Configure TabBar appearance for better contrast in both light and dark modes
28+
// Configure TabBar appearance using UIKit for unselected item color
29+
// This is the only way to set unselected item color in iOS 15+
2930
let appearance = UITabBarAppearance()
3031
appearance.configureWithDefaultBackground()
3132

32-
// Set tint color for selected items
33-
// Light Mode: deep/dark color (from Color.tintColor)
34-
// Dark Mode: white (from Color.tintColor)
35-
UITabBar.appearance().tintColor = UIColor(Color.tintColor)
36-
37-
// Set color for unselected items with subtle difference from selected
38-
// Light mode: selected = dark color, unselected = slightly lighter dark color (60% opacity)
39-
// Dark mode: selected = white, unselected = slightly dimmed white (60% opacity)
33+
// Unselected item color - use specific colors for light/dark mode
4034
let unselectedColor = UIColor { traitCollection in
4135
switch traitCollection.userInterfaceStyle {
4236
case .dark:
43-
// Dark mode: slightly dimmed white (60% opacity for subtle difference)
44-
return UIColor.white.withAlphaComponent(0.6)
37+
// Dark mode: dim gray (60% white)
38+
return UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1.0)
4539
default:
46-
// Light mode: slightly lighter dark color (60% opacity for subtle difference)
47-
return UIColor.black.withAlphaComponent(0.6)
40+
// Light mode: very light gray (78% gray - very subtle)
41+
return UIColor(red: 0.78, green: 0.78, blue: 0.78, alpha: 1.0)
4842
}
4943
}
50-
UITabBar.appearance().unselectedItemTintColor = unselectedColor
44+
45+
appearance.stackedLayoutAppearance.normal.iconColor = unselectedColor
46+
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: unselectedColor]
47+
48+
appearance.inlineLayoutAppearance.normal.iconColor = unselectedColor
49+
appearance.inlineLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: unselectedColor]
50+
51+
appearance.compactInlineLayoutAppearance.normal.iconColor = unselectedColor
52+
appearance.compactInlineLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: unselectedColor]
5153

5254
UITabBar.appearance().standardAppearance = appearance
5355
if #available(iOS 15.0, *) {
@@ -116,6 +118,7 @@ struct MainPage: StateView {
116118
}
117119
.tag(TabId.me)
118120
}
121+
.tint(Color.primary) // Use primary color for selected items (black in light, white in dark)
119122

120123
// Filter menu overlay - only render when needed
121124
if state.selectedTab == .feed && store.appState.feedState.showFilterMenu {

0 commit comments

Comments
 (0)