【问题标题】:setFinishedSelectedImage:withFinishedUnselectedImage: + StoryboardssetFinishedSelectedImage:withFinishedUnselectedImage: + 故事板
【发布时间】:2012-05-07 21:52:39
【问题描述】:

我的界面完全由 Storyboards 布置(包括 UITabBarController 和所有相应的视图)。

现在是自定义标签栏的时候了。因为我的图标已经设置为正确的颜色,所以我不能使用[[UITabBar appearance] setTintColor:](它总是看起来不对)。

原来我应该在特定的 UITabBarItem 上使用 setFinishedSelectedImage:withFinishedUnselectedImage:

是否可以从 AppDelegate 中使用此方法(我的其余全局自定义发生的地方)? AppDelegate 如何知道要定位哪个 UITabBar?

如果相反,我应该从每个 UIViewController 自定义每个 UITabBarItem,我如何引用 UITabBar(或“根视图控制器”?)然后从 UIViewController 中引用特定项目?

任何帮助将不胜感激。 谢谢!

【问题讨论】:

  • 既然您引用了我对您的问题的回答作为已接受的回答,请使用复选标记按钮接受它作为正确答案。谢谢。

标签: iphone ios ios5 user-interface uitabbar


【解决方案1】:

在您的UIViewController 实例中的viewDidLoad 中,您可以这样做

[self.tabBarItem setFinishedSelectedImage: withFinishedUnselectedImage:]

【讨论】:

    【解决方案2】:

    试试这个

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
    
        if (self) {
            [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"t1s"] withFinishedUnselectedImage:[UIImage imageNamed:@"t1"]];
            [self.tabBarItem setTitle:@"Title"];
        }
    
        return self;
    }
    

    另外,从情节提要视图中删除标签栏项目中的图像

    【讨论】:

    • 我建议将完成的图像设置为 viewDidLoad:,因为如果 ViewController 以编程方式加载,initWithCoder: 将不会执行。尽管此特定问题明确引用了 Interface Builder,但其他阅读本文的用户可能并非如此。
    猜你喜欢
    • 1970-01-01
    • 2012-12-18
    • 2012-01-29
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多