Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Map keeps overriding appearance of ToolBar / NavigationBar
Here's a complete example: import SwiftUI import MapKit struct Theme { static let primary = Color.red static let secondary = Color.green static let background = Color.gray } @MainActor struct ViewTabs: View { @State var tag: UInt8 = 1 var body: some View { TabView(selection: $tag) { Map() .tag(0) .tabItem { Label("Map", systemImage: "map") } Text("hello") .tag(1) .tabItem { Label("Text", systemImage: "character") } Image(systemName: "dog") .tag(2) .tabItem { Label("Dog", systemImage: "dog") } } .onAppear(perform: ViewTabs.styleTabBar) } static func styleTabBar () { let normalTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(Theme.secondary)] UITabBarItem.appearance().setTitleTextAttributes(normalTextAttributes, for: .normal) let selectedTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(Theme.primary)] UITabBarItem.appearance().setTitleTextAttributes(normalTextAttributes, for: .selected) let tabBarItemAppearance = UITabBarItemAppearance() tabBarItemAppearance.normal.titleTextAttributes = normalTextAttributes tabBarItemAppearance.normal.iconColor = UIColor(Theme.secondary) tabBarItemAppearance.selected.titleTextAttributes = selectedTextAttributes tabBarItemAppearance.selected.iconColor = UIColor(Theme.primary) let tabBarAppearance = UITabBarAppearance() tabBarAppearance.backgroundColor = UIColor(Theme.background) tabBarAppearance.inlineLayoutAppearance = tabBarItemAppearance tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance tabBarAppearance.compactInlineLayoutAppearance = tabBarItemAppearance UITabBar.appearance().isTranslucent = false UITabBar.appearance().standardAppearance = tabBarAppearance UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance } } #Preview { ViewTabs() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Reply to SwiftUI Map keeps overriding appearance of ToolBar / NavigationBar
I have the same issue. The following code works everywhere except views that have Map() in it. In those, everything seems to be reset to defaults… let normalTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(Theme.secondary)] UITabBarItem.appearance().setTitleTextAttributes(normalTextAttributes, for: .normal) let selectedTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(Theme.primary)] UITabBarItem.appearance().setTitleTextAttributes(normalTextAttributes, for: .selected) let tabBarItemAppearance = UITabBarItemAppearance() tabBarItemAppearance.normal.titleTextAttributes = normalTextAttributes tabBarItemAppearance.normal.iconColor = UIColor(Theme.secondary) tabBarItemAppearance.selected.titleTextAttributes = selectedTextAttributes tabBarItemAppearance.selected.iconColor = UIColor(Theme.primary) let tabBarAppearance = UITabBarAppearance() tabBarAppearance.backgroundColor = UIColor(Theme.background) tabBarAppearance.inlineLayoutAppearance = tabBarItemAppearance tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance tabBarAppearance.compactInlineLayoutAppearance = tabBarItemAppearance UITabBar.appearance().isTranslucent = false UITabBar.appearance().standardAppearance = tabBarAppearance UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance Were you able to solve your issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24