How to set title using UITabbarsystemitem

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

What I've done:

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

So, to change the default title instead of โ€œFeaturedโ€ (due to the UITabBarSystemItemFeatured object), I wrote:

self.tabBarItem.title = @"Actu";

So, in my opinion, I should have "Actu" as the name instead of "Featured".

But it does not change anything, the title remains "Featured" (default name).

I also tried:

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

(because this tabbaritem has an index of 0), but nothing changes.

Or perhaps such a modification is not possible when using UITabBarSystemItem objects?

Hope this will be explained quite well: /

PS: Sorry for my English and something else is wrong, 1st post ever ...: /

+7
source share
5 answers

When a UITabBarItem initialized using initWithTabBarSystemItem:tag: you cannot subsequently change the properties of the image or name.

Source: iOS Development Documentation

+4
source

You can use KVC.

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

+2
source

You already wrote that:

... such a modification is not possible using UITabBarSystemItem objects ...

The title and image objects are set to nil , so they are stored in some internal private properties.

The documents also say:

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

0
source

This is actually possible, you can use the _setInternalTitle: method from the private API.

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

Precautions: Use it only to build tests.

0
source

I understand that this is old, but maybe it will help someone else who wants to do it. Create a tabBarItem from the system element as described above. Then create another tabBarItem as if you have a custom icon and copy the image from the system element.

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

All Articles