如何自定义UITabBar文本标签?

发布于 2024-12-19 20:57:46 字数 1106 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雅心素梦 2024-12-26 20:57:46

您可以通过访问每个视图控制器的选项卡栏的选项卡栏项目对象来完成此操作。
请查看此处的一些文档以获取更多示例。

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

一笑百媚生 2024-12-26 20:57:46

使用它来自定义 UITabBarItem 文本:使用

[[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes];

此处中的答案类似的属性字典。

Use this to customize UITabBarItem text:

[[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes];

with a dictionary of attributes similar to those shown in the answer here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文