iOS 15 标签栏滚动到底部后透明

Vla*_*bir 15 tabbar ios15

如何修复iOS 15标签栏滚动到底部后透明的问题:

iOS 15 透明标签栏

Jos*_*llo 18

在 iOS 15 中,UIKit 扩展了 \xc2\xa0scrollEdgeAppearance 的使用,默认情况下会生成透明背景。

\n

在此输入图像描述

\n

由于我在 iOS 15 之前在应用程序中全局更改了标签栏颜色,因此我已将以下代码添加到我的 AppDelegate 中:

\n
UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"\nUITabBar.appearance().tintColor = "YOUR ICONS COLOR"\nUITabBar.appearance().isTranslucent = true\n
Run Code Online (Sandbox Code Playgroud)\n

为了恢复旧的外观,我采用了新的 UITBar 外观 API,UITabBarAppearance。我将代码更改为:

\n
    UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"\n    UITabBar.appearance().tintColor = "YOUR ICONS COLOR"\n    UITabBar.appearance().isTranslucent = true\n\n    if #available(iOS 15.0, *) {\n        let appearance = UITabBarAppearance()\n        appearance.configureWithOpaqueBackground()\n        appearance.backgroundColor = "YOUR UITABBAR COLOR"\n        UITabBar.appearance().standardAppearance = appearance\n        UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

结果,我得到了 UITabBar 的原始颜色\n在此输入图像描述

\n


Vla*_*bir 11

在 iOS 15 中,Apple 添加了scrollEdgeAppearance用于配置边缘滚动时选项卡栏外观的属性。

https://developer.apple.com/documentation/uikit/uitabbar/3750912-scrolledgeappearance?changes=latest_minor

滚动边缘外观

要修复透明选项卡栏,您应该创建自定义滚动边缘外观并将其设置到选项卡栏。

if #available(iOS 15.0, *) {
   let appearance = UITabBarAppearance()
   appearance.backgroundEffect = UIBlurEffect(style: .light)
   tabBar.scrollEdgeAppearance = appearance
}
Run Code Online (Sandbox Code Playgroud)

结果: iOS 15 标签栏不透明


san*_*orb 6

init() {
    if #available(iOS 15, *) {
        let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
           tabBarAppearance.configureWithOpaqueBackground()
            UITabBar.appearance().standardAppearance = tabBarAppearance
            UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这个答案就目前而言很有用。 (2认同)