tags:

views:

70

answers:

3

HI all

how can we set titles of tab bars programmatically.

i have five tabs in my main window.But i hvnt created it programmatically. what should i do ? how to give title through code?

regards shishir

A: 

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.

Chintan Patel
thanks man,i only need to provide name programmatially, rest will be the same...any other way to provide title manually???
shishir.bobby
A: 

OR

[(UIViewController *)[tabBarController.viewControllers objectAtIndex:1] setTitle:@"Title1"];
mihirpmehta
it is right answer... don't down vote it just because you can't understand it or it doesn't match with your opinion..
mihirpmehta
+1  A: 

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.

Thanks,

Madhup

Madhup
i was trying to set title of tab bar button.wat i just did is just provided self.title = @"Title";at viewdidload..and tab bar's as well as viewcontroller's title has beeen set to "title."is this proper?????
shishir.bobby
@shishir.bobby can't say if it is right or not
Madhup
No need to set the title at both place... Any one would be adequate...
mihirpmehta