Lucien
Lucien

Reputation: 451

How to set title with UITabbarsystemitem

I just wanted to know how i can set a title of a tab bar item using UITabBarSystemItem ?

What i did :

self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];

So to change the title by default instead of "Featured" (because of UITabBarSystemItemFeatured object), I wrote :

self.tabBarItem.title = @"Actu";

So in my mind i should have "Actu" as title instead of "Featured".

But it changes nothing, the title keeps being "Featured" (default title).

I also tried :

[[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"Actu", @"Actu")];

(because this tabbaritem is at index 0), but nothing changes.

Or maybe such a modification is not possible using UITabBarSystemItem objects ?

I hope this is well enough explained :/

PS : Sorry for my english and anything else wrong, 1st post ever… :/

Upvotes: 7

Views: 3394

Answers (5)

Heisenbean
Heisenbean

Reputation: 61

You can use KVC.

[self.tabBarItem.setValue("YourTitle", forKey: "internalTitle")];

Upvotes: 3

Roman B.
Roman B.

Reputation: 3638

Actually it is possible, you can utilize method _setInternalTitle: from private API.

[self.tabBarItem setValue:@"Categories" forKey:@"internalTitle"];

Precaution: use it only for test builds.

Upvotes: 1

Philip Nelson
Philip Nelson

Reputation: 995

I realize this is old, but perhaps this would help somebody else that wants to do this. Create a tabBarItem from the system item as indicated above. Then create another tabBarItem as if you had a custom icon and copy the image from the system item.

        UITabBarItem* systemItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
        UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:theNameIWantToUse image:systemItem.image tag:0];

Upvotes: -3

Leon Lucardie
Leon Lucardie

Reputation: 9740

When a UITabBarItem is initalized using initWithTabBarSystemItem:tag: you cannot change the image or title properties later on.

Source: iOS Development Documentation

Upvotes: 4

Tricertops
Tricertops

Reputation: 8512

You already wrote that:

… such a modification is not possible using UITabBarSystemItem objects…

Those have title and image properties set to nil, so they have these values stored in some internal private properties.

Also the docs say:

-initWithTabBarSystemItem:tag:
The title and image properties of the returned item cannot be changed later.

Upvotes: 1

Related Questions