gpt4 book ai didi

ios - 保留选中和未选中的 UITabBar 图标的原始图像颜色

转载 作者:IT王子 更新时间:2023-10-29 08:16:51 25 4
gpt4 key购买 nike

结构如下:

在我的 Storyboard中,我有一个 Tab Bar Controller,其中包含一个 Tab Bar 对象。这个对象有一个自定义类,其中我只有这个方法:

- (void)awakeFromNib
{
NSArray *imageNames = @[@"test1", @"test2", @"test3", @"test4", @"test5"];
for (int i=0; i<5; i++) {
UITabBarItem *item = [self.items objectAtIndex:i];
NSString *imageName = [imageNames objectAtIndex:i];
item.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.selectedImage = [UIImage imageNamed:[imageName stringByAppendingString:@"-selected"]];
}
}

我创建了一个 Asset Catalog,其中包含我的选项卡栏图标,包括选中和未选中的版本(不同颜色)。

documentation UIImageRenderingModeAlwaysOriginal 提到始终绘制原始图像,而不将其视为模板。 应保留原始图像颜色。这似乎并没有发生并且this建议也没有用。

相反的是,在选中状态下,我的标签栏图标获得默认的蓝色色调。

我注意到的一件事是,如果我在 AppDelegatedidFinishLaunchingWithOptions 中执行以下操作(取自 here),那么我可以设置颜色根据需要选择标签栏图标:

[[UITabBar appearance] setTintColor:[UIColor purpleColor]];

setTintColor 的文档提到:

The tint color to apply to the tab bar’s tab bar items. Starting in iOS 7.0, the tint color that applies to a tab bar’s tab bar items is the first nondefault tint color in the view hierarchy, starting with the tab bar itself.

这是否意味着无论我的标签栏图标的颜色如何(图像本身的原始颜色),在选定状态下它们将始终具有 tintColor 的颜色?

还是我做错了什么/遗漏了什么?

我在 iOS 7.0 和 7.1 上遇到了这个问题。

最佳答案

只需转到您的图像 Assets 属性,并将 Render as 属性设置为“原始图像”

enter image description here

然后你就可以开始了!

关于ios - 保留选中和未选中的 UITabBar 图标的原始图像颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846652/

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