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

≯℡__Kan透↙ 提交于 2019-11-26 11:34:10

问题


I have an application with UITabbar , I want to set image in Tabbar but am unable to set image in Tabbar. Instead of as it is image i get image shape in tint color, Is it possible to set image as it is in Tabbar? .

i have Tried this code but Unable to set image.

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

回答1:


You need to set your image attributes property Render As to Original Image. To change this select your image from assets and in the Attributes Inspector set Render As property to Original Image like this.




回答2:


Select your TabBar Item and set your image like this

OR

Set selected tint color try this

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


来源:https://stackoverflow.com/questions/38560105/how-to-set-image-in-tabbar-not-tint-color-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!