【发布时间】:2021-08-26 04:50:13
【问题描述】:
【问题讨论】:
【问题讨论】:
在 iOS 15 中,Apple 添加了 scrollEdgeAppearance 属性,用于在边缘滚动时配置标签栏的外观。
要修复透明标签栏,您应该创建自定义滚动边缘外观并将其设置为标签栏。
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.backgroundEffect = UIBlurEffect(style: .light)
tabBar.scrollEdgeAppearance = appearance
}
【讨论】:
init() {
if #available(iOS 15, *) {
let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
tabBarAppearance.configureWithOpaqueBackground()
UITabBar.appearance().standardAppearance = tabBarAppearance
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}
}
【讨论】:
在 iOS 15 中,UIKit 扩展了scrollEdgeAppearance 的使用,默认情况下会生成透明背景。
由于我在我的应用中全局更改了标签栏颜色,在 iOS 15 之前,我已将以下代码添加到我的 AppDelegate:
UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().tintColor = "YOUR ICONS COLOR"
UITabBar.appearance().isTranslucent = true
为了恢复旧的外观,我采用了新的 UITBar 外观 API,UITabBarAppearance。我将代码更改为:
UITabBar.appearance().barTintColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().tintColor = "YOUR ICONS COLOR"
UITabBar.appearance().isTranslucent = true
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = "YOUR UITABBAR COLOR"
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
【讨论】: