当我将 isTranslucent 设置为 false 并结合 NavigationView 时,我的选项卡式 View 出现了一些问题。
有人知道怎么解决吗?问题如附图所示。
我需要将半透明设置为 false,否则我无法获得深色。
最佳答案
您可以设置背景颜色。不要将 isTranslucent 设置为 false,否则会产生您提到的这些人工制品。
UITabBar.appearance().backgroundColor = .black
UINavigationBar.appearance().backgroundColor = .black
它变得更暗了。不过它并非完全不透明。
编辑:刚刚观看了 Modernizing Your UI for iOS 13 这是这样做的方法:
TabView 和 NavigationView 实际上是遗留 UITabBarController 和 UINavigationController 的 UIHostedController:
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor .white]
然后在各种类型的外观上设置外观。
tabBar.standardAppearance = appearance
第二次编辑:
extension UINavigationController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
navigationBar.standardAppearance = appearance
navigationBar.compactAppearance = appearance
navigationBar.scrollEdgeAppearance = appearance
}
}
extension UITabBarController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
tabBar.standardAppearance = appearance
}
}
应该有一种更简洁的方式来访问 tabBar 和 navBar。
关于SwiftUI - TabView with NavigationView 生成灰色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017776/