gpt4 book ai didi

swift - UITabBarController 图像太小

转载 作者:行者123 更新时间:2023-11-30 10:59:03 25 4
gpt4 key购买 nike

我有 3 个版本的图像,75 x 75、50 x 50 和 25 x 25。

当我将其设置为标签栏图像时,我得到以下效果:

我期望图像更大,但似乎无法编辑它。

我已经以编程方式构建了我的 UITabBarController 。

class MainTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()
navigationController?.isNavigationBarHidden = true

tabBar.isTranslucent = false
tabBar.barTintColor = UIColor.hexStringToUIColor(hex: "EFF4EF")

viewControllers = [
generateNavigationController(with: ChatBotController(), image: #imageLiteral(resourceName: "tabBar_bot_head").withRenderingMode(.alwaysOriginal)),
]
}

fileprivate func generateNavigationController(with rootViewController: UIViewController, image: UIImage) -> UIViewController {
let navController = UINavigationController(rootViewController: rootViewController)
navController.tabBarItem.image = image
return navController
}
}

最佳答案

尝试在 UIImage 扩展中添加此功能

extension UIImage {

func resize(targetSize: CGSize) -> UIImage {
return UIGraphicsImageRenderer(size:targetSize).image { _ in
self.draw(in: CGRect(origin: .zero, size: targetSize))
}
}

}

并在viewDidLoad中更改代码行

viewControllers = [
generateNavigationController(with: ChatBotController(), image: #imageLiteral(resourceName: "tabBar_bot_head").withRenderingMode(.alwaysOriginal)),
]

有了这个

viewControllers = [
generateNavigationController(with: ChatBotController(), image: #imageLiteral(resourceName: "tabBar_bot_head").withRenderingMode(.alwaysOriginal)).resize(targetSize: CGSize(width: 50, height: 50)),
]

关于swift - UITabBarController 图像太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53613389/

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