如何在TabBar中设置图像不在tos颜色?

我有一个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]; 

您需要将您的图像属性属性Render AsOriginal Image 。 要改变这个,从资源中select你的图像,并在Attributes Inspector中将Render As属性设置为Original Image

在这里输入图像说明

select您的TabBar项目,并像这样设置你的图像

在这里输入图像说明

要么

设置选定的色调颜色试试这个

 [[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]];