如何在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 As
为Original 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]];