如何在代码中设置iPhone标签栏图标? [英] How to set iPhone tab bar icon in code?

查看:110
本文介绍了如何在代码中设置iPhone标签栏图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用相同的ViewController几个不同的视图。

I am using the same ViewController for several different views.

在为特定视图实例化ViewController时,是否有通过代码指定标签栏图标的简单方法?

When instantiating the ViewController for a specific view, is there an easy way to specify the tab bar icon via code?

推荐答案

yourViewController.tabBarItem = [[UITabBarItem alloc]
initWithTitle:NSLocalizedString(@"Name", @"Name")
image:[UIImage imageNamed:@"tab_ yourViewController.png"]
tag:3];

viewControllers已添加到选项卡栏,因此图像和名称应在标签栏变为可见(appDelegate,如果他们在应用程序启动例如)。之后,您可以使用上述代码更改viewController中的loadView或viewDidAppear的图标和文本。

The viewControllers are added to the tab bar, so the image and names should be set before the tab bar becomes visible (appDelegate if they are there on app start for instance). After that, you could use the above code to change the icon and text from the loadView or viewDidAppear within that viewController.

这篇关于如何在代码中设置iPhone标签栏图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆