【问题标题】:How to customize UITabBar text labels?如何自定义 UITabBar 文本标签?
【发布时间】:2014-01-28 07:33:54
【问题描述】:

我使用 Ray Wenderlich 和 iOS 博客中的方法自定义了一个标签栏,但是因为我使用浅色作为背景,所以文本标签看起来很糟糕,我想更改它们以匹配我的风格。有可能吗?如何实现?

如果不可能或太复杂,我想问一下如何将图标图像向下移动以使其位于标签栏的中心?这样我可以在 .png 文件上“写”标签。

我正计划为 iOS5+ 开发这个应用程序,因此无需担心使其与 iOS4 兼容(尽管如果有人找到一种简单的方法,我将不胜感激。

这里是what I got,这里是what I want

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

【问题讨论】:

    标签: iphone objective-c ios ios5 uitabbar


    【解决方案1】:

    您可以通过访问每个视图控制器的标签栏的标签栏项目对象来做到这一点。 在此处查看一些文档以获取更多示例。

    http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html

    【讨论】:

      【解决方案2】:

      使用它来自定义 UITabBarItem 文本:

      [[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes];
      

      具有类似于答案here 中显示的属性字典。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-15
        • 2012-05-15
        • 2011-02-03
        • 1970-01-01
        • 1970-01-01
        • 2012-10-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多