Programmatically Creating and Configuring UITabBarController - System Configuration Image for Tab

Creating a tabBar in an application programmatically is quite simple:

self.tabBarController = [[UITabBarController alloc] init]; 
[self.view addSubview:_tabBarController.view];

UIViewController * tab1 = [[UIViewController alloc] init];
tab1.title = "A";

UIViewController * tab2 = [[UIViewController alloc] init];
tab2.title = "B";

_tabBarController.viewControllers = [NSArray arrayWithObjects:patientSearch,todoList,nil];

[tab1 release];
[tab2 release];

You can also easily place images on tabs:

tab1.tabBarItem.image = [UIImage imageNamed:@"myIcon.png"];

However, how can I set the image of these tabs to a single system image? (e.g. search, favorites, bookmarks, etc.). In IB, this is set by changing the "identifier", but how can you do this programmatically

+5
source share
1 answer
 UITabBarItem *aTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];

UITabBarItem docs

UITabBarSystemItem System items that can be used in the tab bar.

typedef enum {
   UITabBarSystemItemMore,
   UITabBarSystemItemFavorites,
   UITabBarSystemItemFeatured,
   UITabBarSystemItemTopRated,
   UITabBarSystemItemRecents,
   UITabBarSystemItemContacts,
   UITabBarSystemItemHistory,
   UITabBarSystemItemBookmarks,
   UITabBarSystemItemSearch,
   UITabBarSystemItemDownloads,
   UITabBarSystemItemMostRecent,
   UITabBarSystemItemMostViewed,
} UITabBarSystemItem;

To install it patientSearch.tabBarItem = aTabBarItem;

+10

All Articles