以编程方式设置标签栏的标题

时间:2010-06-17 09:58:59

标签: iphone tabs

我的主窗口中有五个选项卡,但我还没有以编程方式创建它。

如何通过代码创建标题?

4 个答案:

答案 0 :(得分:12)

嘿,您是否要设置标签栏按钮的标题或与标签关联的视图控件?

如果您正在寻找第一件事,那就这样做:

UITabBarItem *tabItem = [[[tabBarController tabBar] items] objectAtIndex:yourIndex];
[tabItem setTitle:@"theTitle"];

否则mihirpmehta是正确的。

希望这有帮助。

答案 1 :(得分:5)

OR

[(UIViewController *)[tabBarController.viewControllers objectAtIndex:1] setTitle:@"Title1"];

答案 2 :(得分:0)

您可以使用以下函数初始化和使用UITabBarItem对象:

- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag; // selected image autogenerated
- (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag

然后你可以在你的tabBar对象上调用这个方法:

- (void)setItems:(NSArray *)items animated:(BOOL)animated;

其中items为您添加了所有tabBarItem对象的数组。如果需要使用,还有UITabBarItem的badgeValue属性。

答案 3 :(得分:0)

如果您的UIViewController包含在UINavigationController中,请执行以下操作:

self.navigationController?.tabBarItem.title = "Awesome Title"
相关问题