其中有这样一句话:If the value of this property is nil
, UIKit uses the value of the tab bar’s standardAppearance
property, modified to have a transparent background. 如果这个属性为nil,UIKit将使用[standardAppearance](doc://com.apple.documentation/documentation/uikit/uitabbar/3198046-standardappearance?language=occ)
属性,设置为透明的背景
这样的话我们只需要让scrollEdgeAppearance属性不为nil即可。
解决代码1:
if (@available(iOS 15.0, *)) {
self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance;
}
解决代码2:
if (@available(iOS 15.0, *)) {
//新建一个UITabBarAppearance,设置你想要的即可
UITabBarAppearance * appearance = [UITabBarAppearance new];
// appearance.backgroundImage = [Tools imageWithColor:[ColorUtil bgColor]];//设置背景图片也可
appearance.backgroundColor = [ColorUtil bgColor];//设置背景颜色也可以
self.tabBar.scrollEdgeAppearance = appearance;
}
网友评论