gpt4 book ai didi

ios - 更改未选择的标签栏项目的颜色

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

我有一个标签栏 Controller ,我已经设法将选定的标签图像和标题设为黑色,将未选定的项目标题设为白色,但我无法将未选定的项目图像设为白色。

在我的标签栏 Controller 中:-(无效)viewDidLoad{

    [super viewDidLoad];
// Do any additional setup after loading the view.

UIColor *customColor = [UIColor colorWithRed:179.0/255.0f green:155.0/255.0f blue:107.0/255.0f alpha:1];

[self.tabBar setBarTintColor:customColor];

[self.tabBar setSelectedImageTintColor:[UIColor blackColor]];

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];

UITabBarItem *item0 = [self.tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [self.tabBar.items objectAtIndex:2];

item0.image = [[UIImage imageNamed:@"home_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item0.selectedImage = [UIImage imageNamed:@"home_tab"];
item1.image = [[UIImage imageNamed:@"contact_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:@"contact_tab"];
item2.image = [[UIImage imageNamed:@"about_unselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item2.selectedImage = [UIImage imageNamed:@"about_tab"];
}

enter image description here

最佳答案

我是这样工作的:

标签栏 Controller :

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

UIColor *customColor = [UIColor colorWithRed:179.0/255.0f green:155.0/255.0f blue:107.0/255.0f alpha:1];

[self.tabBar setBarTintColor:customColor];
[self.tabBar setTintColor:[UIColor blackColor]];

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
}

在标签栏上的三个 View Controller 中的每一个中:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.title = NSLocalizedString(@"Home", @"Home");
self.tabBarItem.image = [[UIImage imageNamed:@"home_unselected"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem.selectedImage = [UIImage imageNamed:@"home_tab"];
}
return self;
}

关于ios - 更改未选择的标签栏项目的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23875285/

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