gpt4 book ai didi

ios - tabbaritem 图像未更改

转载 作者:行者123 更新时间:2023-11-29 00:51:55 26 4
gpt4 key购买 nike

我正在根据上下文更改 tabBarItem 的图像

    if (user == nil) {
self.navigationController?.tabBarItem.title = "Login"
self.navigationController?.tabBarItem.image = UIImage(named: "login")
} else {
self.navigationController?.tabBarItem.title = "Home"
self.navigationController?.tabBarItem.image = UIImage(named: "home")
self.view = homeView()
}

但是当我将 View 替换为 homeView 时,图像不会更改,但标题会更改。

Logged screeen

一旦我切换到其他项目,我就会更改它: enter image description here

如何在重定向到 HomeView 后立即更改它?

最佳答案

我想我发现了问题(尚未测试)。它不起作用,因为 tabBar 的图像和它的selected 图像之间存在差异。只需添加这一行:

else {
self.navigationController?.tabBarItem.title = "Home"
self.navigationController?.tabBarItem.image = UIImage(named: "home")
self.navigationController?.tabBarItem.selectedImage = UIImage(named: "home")
self.view = homeView()
}

关于ios - tabbaritem 图像未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38038119/

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