我有一个带有SwiftUI的TabBar应用程序。如果我从NavigationView中打开一个详细子视图,然后单击"Back",TabBar就会变得透明,在TabBar图标下面显示Feed中的项目。
从主提要

然后,


发布于 2021-10-06 14:24:32
通过iOS 15,苹果已经将对scrollEdgeAppearance的支持扩展到了UIKit。默认情况下,此设置生成透明的TabBar背景。
要解决这个问题,请将下面的代码添加到SceneDelegate文件中,以定义TabBar的颜色,这样SwiftUI就不会自动使其透明。
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = (scene as? UIWindowScene) else { return }
// MARK: ADD THIS CODE BELOW TO YOUR SCENE DELEGATE.
// TAB BAR BACKGROUND COLOR HERE.
UITabBar.appearance().barTintColor = UIColor.white
// TAB BAR ICONS COLOR HERE.
UITabBar.appearance().tintColor = UIColor.blue
UITabBar.appearance().isTranslucent = true
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
// TAB BAR BACKGROUND COLOR HERE. (same as above)
appearance.backgroundColor = UIColor.white
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: RootView())
self.window = window
window.makeKeyAndVisible()
}
}发布于 2022-01-31 04:15:10
这是我所需要做的。
if #available(iOS 15.0, *) {
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.configureWithDefaultBackground()
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}https://stackoverflow.com/questions/69467580
复制相似问题