Reputation: 10984
I have five tabs in my main window, but I haven't created it programmatically.
What should I do to create the title through code?
Upvotes: 5
Views: 5126
Reputation: 926
If your UIViewController
is wrapped in a UINavigationController
, do the following:
self.navigationController?.tabBarItem.title = "Awesome Title"
Upvotes: 0
Reputation: 8124
Hey do you want to set the title of the tab bar button or the viewcontroller that is associated with the tab?
If you are looking for the first thing then do it like:
UITabBarItem *tabItem = [[[tabBarController tabBar] items] objectAtIndex:yourIndex];
[tabItem setTitle:@"theTitle"];
otherwise mihirpmehta
is correct.
Hope this helps.
Upvotes: 12
Reputation: 13843
OR
[(UIViewController *)[tabBarController.viewControllers objectAtIndex:1] setTitle:@"Title1"];
Upvotes: 5
Reputation: 3165
You can initialize and use a UITabBarItem object using the following functions:
- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag; // selected image autogenerated
- (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag
And then you can call this method on your tabBar object:
- (void)setItems:(NSArray *)items animated:(BOOL)animated;
where items id the array to which you have added all your tabBarItem objects. There is also a badgeValue property for UITabBarItem if you need to use.
Upvotes: 0