如何自定义UITabBar文本标签?
我使用 Ray Wenderlich 和 iOS 博客中的方法自定义了一个选项卡栏,但因为我使用浅色作为背景,所以文本标签看起来很糟糕,我想更改它们以符合我的风格。这可能吗?如何实现?
如果不可能或者太复杂,我想问如何向下移动图标图像,使其位于选项卡栏的中心?这样我就可以在 .png 文件上“写入”标签。
我计划为 iOS5+ 开发这个应用程序,因此不用担心它与 iOS4 兼容(尽管如果有人找到一种简单的方法来做到这一点,我将非常感激)。
我的 tabBarBackground 的代码:
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selection-tab.png"]];
和图标的代码:
//Custom TabBar Items
UIImage *selectedImage = [UIImage imageNamed:@"home-icon-selected.png"];
UIImage *unselectedImage = [UIImage imageNamed:@"home-icon.png"];
UITabBar *tabBar = rootTabBarController.tabBar;
//Icons for the 1st Tab
UITabBarItem *item1 = [tabBar.items objectAtIndex:0];
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
I have customized a Tab Bar using the methods from Ray Wenderlich and iOS Blog but because I'm using a light color as background the text labels look awful and I want to change them to match my style. Is it possible and how?
If its not possible or if its too complex I would like to ask how to move the icon image down so its centered on the Tab Bar? This way I could "write" the labels on the .png files.
I'm planning on developing this app for iOS5+ so there is no worry about making it compatible with iOS4 (although if anyone finds a easy way of doing this I would really appreciate).
Here's what I got so far and here's what I want.
The code for my tabBarBackground:
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selection-tab.png"]];
And for the Icons:
//Custom TabBar Items
UIImage *selectedImage = [UIImage imageNamed:@"home-icon-selected.png"];
UIImage *unselectedImage = [UIImage imageNamed:@"home-icon.png"];
UITabBar *tabBar = rootTabBarController.tabBar;
//Icons for the 1st Tab
UITabBarItem *item1 = [tabBar.items objectAtIndex:0];
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过访问每个视图控制器的选项卡栏的选项卡栏项目对象来完成此操作。
请查看此处的一些文档以获取更多示例。
http://developer.apple.com/library/ios/ #featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html
You can do this by accessing the tab-bar item object of the tabbar for each view controller.
Check out some documentation here for more examples.
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html
使用它来自定义 UITabBarItem 文本:使用
与此处中的答案类似的属性字典。
Use this to customize UITabBarItem text:
with a dictionary of attributes similar to those shown in the answer here.