自定义UITabBar图标iOS [英] Custom UITabBar icons iOS
本文介绍了自定义UITabBar图标iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个选项卡式应用程序,我想集成自定义的UITabbar背景和图标.我已经插入了自定义背景,但是图标有问题.
I am developing a tabbed application and i want to integrate custom UITabbar background and icons. I already inserted a custom background but i have a problem with the icons.
这是图标的外观:
但是在情节提要中为每个视图添加图标后,我会得到如下灰色图标:
But after adding the icons for each view in the storyboard i get grey icons like this:
有人知道为什么以这种方式显示图标吗?
Does anyone have an idea why the icons are displayed this way?
非常感谢!
推荐答案
这是我在其中一个应用程序中执行的操作.在您的AppDelegates didFinishLaunchingWithOptions:
方法中,添加此方法并填写图像名称:
This is how I do it in one of my apps. In your AppDelegates didFinishLaunchingWithOptions:
method, add this and fill in your image names:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
//tab1
UIImage *selectedImage = [UIImage imageNamed:@"home-tab-selected"];
UIImage *unselectedImage = [UIImage imageNamed:@"home2-tab"];
MyTabBar *tabBar = (MyTabBar *)tabController.tabBar;
UITabBarItem *item1 = [tabBar.items objectAtIndex:0];
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
//tab2
selectedImage = [UIImage imageNamed:@"customers-tab-selected"];
unselectedImage = [UIImage imageNamed:@"customers-tab"];
UITabBarItem *item2 = [tabBar.items objectAtIndex:1];
[item2 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
//tab3
selectedImage = [UIImage imageNamed:@"maps-tab-selected"];
unselectedImage = [UIImage imageNamed:@"maps-tab"];
UITabBarItem *item3 = [tabBar.items objectAtIndex:2];
[item3 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
//tab4
selectedImage = [UIImage imageNamed:@"reports-tab-selected"];
unselectedImage = [UIImage imageNamed:@"reports-tab"];
UITabBarItem *item4 = [tabBar.items objectAtIndex:3];
[item4 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
//tab5
selectedImage = [UIImage imageNamed:@"orders-tab-selected"];
unselectedImage = [UIImage imageNamed:@"orders-tab"];
UITabBarItem *item5 = [tabBar.items objectAtIndex:4];
[item5 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
{
// ios 5 code here
[tabBar setBackgroundImage:[UIImage imageNamed:@"tab-bg"]];
}
对我来说很完美.
这篇关于自定义UITabBar图标iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文