iOS 5 custom tab bar image vertical alignment(iOS 5 自定义标签栏图像垂直对齐)
问题描述
我的自定义标签栏出现了一些奇怪的行为.图像似乎对齐不正确.这是一个截图(我已经删除了我自己的标签栏背景以突出我的问题):
I'm getting some odd behaviour with my custom tab bar. The images seem to be aligned incorrectly. Here is a screenshot (I have removed my own tab bar background to highlight my problem):
这是我用来为每个状态设置图像的代码:
Here is the code I'm using to set the images for each state:
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeNavController, whatsOnNavController, mapNavController, infoNavController, nil];
self.tabBarController.delegate = self;
// For iOS 5 only - custom tabs
if ([self.tabBarController.tabBar respondsToSelector:@selector(selectedImageTintColor)])
{
// Set the background images
//[[UITabBar appearance] setBackgroundImage: [UIImage imageNamed:@"nav_bg.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"nav_over.png"]];
[homeNavController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"nav_home_over"] withFinishedUnselectedImage:[UIImage imageNamed:@"nav_home"]];
[whatsOnNavController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"nav_whats_on_over"] withFinishedUnselectedImage:[UIImage imageNamed:@"nav_whats_on"]];
[mapNavController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"nav_map_over"] withFinishedUnselectedImage:[UIImage imageNamed:@"nav_map"]];
[infoNavController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"nav_info_over"] withFinishedUnselectedImage:[UIImage imageNamed:@"nav_info"]];
}
我的所有替换标签图像的大小都正确(非视网膜版本为 49 像素高和 80 像素宽).
All of my replacement tab images are correctly sized (49 pixels high and 80 pixels wide for the non-retina versions).
什么可能导致这种奇怪的行为?
What could be causing this odd behaviour?
这是一个更新的屏幕截图,背景已经到位:
Here is an updated screenshot with the background in place:
推荐答案
事实证明,您应该始终在 tabitem 中包含文本.该空间是由空白文本创建的.
It turns out that you should always have text inside a tabitem. The space was created by blank text.
这篇关于iOS 5 自定义标签栏图像垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 5 自定义标签栏图像垂直对齐
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01