将标签栏设置为透明但无法将其恢复为默认样式

set tab bar to transparent but can't bring it back to default style

我可以使用下面的代码将我的 tabBar 设置为透明,但我不知道如何将其恢复为默认样式。如果可以请帮忙,非常感谢!

tabBarController?.tabBar.backgroundColor = .clear
    tabBarController?.tabBar.backgroundImage = UIImage()
    tabBarController?.tabBar.shadowImage = UIImage()

在将标签栏设置为清除颜色之前保存所有属性

let originalBackgroundImage = tabBarController?.tabBar.backgroundImage
let originalshadowImage = tabBarController?.tabBar.shadowImage
let originalbackgroundColor = tabBarController?.tabBar.backgroundColor

然后改成透明色

tabBarController?.tabBar.backgroundColor = .clear
tabBarController?.tabBar.backgroundImage = UIImage()
tabBarController?.tabBar.shadowImage = UIImage()

终于在你需要它的时候回来了

 tabBarController?.tabBar.backgroundColor = originalbackgroundColor
 tabBarController?.tabBar.backgroundImage = originalBackgroundImage
 tabBarController?.tabBar.shadowImage = originalshadowImage

最后在 tabBar 上调用 layoutIfNeeded 希望对你有帮助