如何在 Tabbar 中设置 Image 而不是 ios 中的 Tint color?

How to set Image in Tabbar not Tint color in ios?

我有一个带有 UITabbar 的应用程序,我想在 Tabbar 中设置图像,但无法在 Tabbar 中设置图像。而不是因为它是图像我得到色调颜色的图像形状,是否可以将图像设置为 Tabbar 中的图像? .

我已经尝试过此代码但无法设置图像。

UITabBar *tabBar = self.tabBar;

UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0]; // whichever tab-item
UIImage *selectedIcon = [UIImage imageNamed:@"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];

Select 你的 TabBar Item 并像这样设置你的图片

设置选定的色调试试这个

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

    [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"name-of-selected-image.png"]];
    [[UITabBar appearance]setSelectedItem:[[UITabBar appearance].items objectAtIndex:2]];

您需要将图像属性 属性 Render As 设置为 Original Image。要从资产中更改此 select 图像,并在 Attributes Inspector 中将 Render As 属性 设置为 Original Image,如下所示。