gpt4 book ai didi

ios - UITabBarItem 图像在单击时正在更改图像

转载 作者:行者123 更新时间:2023-11-29 10:31:45 29 4
gpt4 key购买 nike

我会尽量解释我的问题。

当我的应用程序启动时,它会在 appdelegate 类中进行检查:

 if([[NSUserDefaults standardUserDefaults] boolForKey:@"checkboxClicked"]){

tabBarItem3.image = [UIImage imageNamed:@"lock-open"];
tabBarItem3.title = @"Logga ut";
}

else{
tabBarItem3.title = @"Logga In";
tabBarItem3.image = [UIImage imageNamed:@"lock.png"];
}

本质上,它决定图像是否应该是锁定的或未锁定的,并带有相应的标题。现在一切正常,应该显示图像。

场景 1) 用户启动应用程序,图像以“锁定打开”图像开始。稍后用户转到注销页面并注销用户。之后单击应更改其图像的 UITabBarItem 时,它仍显示图像“锁定打开”。但是,当用户单击另一个 UITabBarItem 时,将显示正确的图像。注意 标题始终设置正确。只是图像在做奇怪的事情。

场景 2) 反之亦然,用户以注销等方式启动。

这是我用来更改图像的代码:

  UITabBarItem *item = self.tabBarController.tabBar.items[2];
item.image = [UIImage imageNamed:@"lock"];
item.title = @"Logga in";

最佳答案

使用下面的代码更改UITabBarItem的图像

UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
item0.image = [[UIImage imageNamed:@"lock.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [UIImage imageNamed:@"lock-selected.png"];

关于ios - UITabBarItem 图像在单击时正在更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253092/

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