Iphone 以编程方式设置选项卡栏的标题

Iphone 以编程方式设置选项卡栏的标题,iphone,tabs,Iphone,Tabs,我的主窗口中有五个选项卡,但我没有以编程方式创建它 如何通过代码创建标题?您可以使用以下函数初始化和使用UITabBarItem对象: - (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag; // selected image autogenerated - (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NS

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


如何通过代码创建标题?

您可以使用以下函数初始化和使用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;
where items标识已将所有tabBarItem对象添加到的数组。如果需要使用,UITabBarItem还有一个badgeValue属性

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

嘿,是否要设置选项卡栏按钮的标题或与该选项卡关联的viewcontroller

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

UITabBarItem *tabItem = [[[tabBarController tabBar] items] objectAtIndex:yourIndex];
[tabItem setTitle:@"theTitle"];
否则,
mihirpmehta
是正确的


希望这有帮助。

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

self.navigationController?.tabBarItem.title = "Awesome Title"

谢谢,我只需要提供程序名称,其余的将是一样的。。。还有其他手动提供标题的方法吗???我试图设置选项卡栏按钮的标题。我刚才做的只是提供了self.title=@“title”;在viewdidload。。选项卡栏和viewcontroller的标题都被设置为“标题”。这是正确的吗?这是正确的答案。。。不要仅仅因为你不理解它或者它与你的意见不符就投反对票。。