gpt4 book ai didi

ios - UItabar不能变色或透明

转载 作者:行者123 更新时间:2023-11-28 05:56:23 26 4
gpt4 key购买 nike

我已经实现了下面的代码,使 tabBar 透明,但它根本没有生效,我错过了什么吗?我在 UItabbarcontroller 中有这段代码。

 mainTabbar.barTintColor = .clear
mainTabbar.tintColor = .black

mainTabbar.backgroundImage = UIImage()
mainTabbar.shadowImage = UIImage()

最佳答案

使用这个

func configureTabBar(tabBarController:UITabBarController) {
//Tab bar customization
tabBarController.tabBar.backgroundImage = coloredImage(size: UIScreen.main.bounds.size, restrictedToRect: CGRect(x: 0, y: 0, width: (tabBarController.tabBar.frame.size.width),height: (tabBarController.tabBar.frame.size.height)), color: UIColor.clear)
tabBarController.tabBar.shadowImage = UIImage()
}

然后使用这个方法创建清晰的颜色UIImage

func coloredImage(size:CGSize,restrictedToRect:CGRect,color:UIColor) -> UIImage{

let colorView = UIView(frame: CGRect(origin:CGPoint(x: 0, y: 0) , size: size))
colorView.backgroundColor = color
colorView.contentScaleFactor = UIScreen.main.scale

UIGraphicsBeginImageContextWithOptions(restrictedToRect.size, false, UIScreen.main.scale)
colorView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}

使用示例

if let tabBarController = self.window?.rootViewController as? UITabBarController {
self.configureTabBar(tabBarController: tabBarController)
}

关于ios - UItabar不能变色或透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51397851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com