Creating a tabBar in an app programatically is fairly easy:
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 put images in the tabs:
tab1.tabBarItem.image = [UIImage imageNamed:@"myIcon.png"];
However how can i set the image of these tabs to one the system images? (eg. search, favourite, bookmarks etc.) In IB this is set by changing the 'identifier' but how can you do this programatically
UITabBarItem *aTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
UITabBarItem docs
UITabBarSystemItem System items that can be used on a tab bar.
typedef enum {
UITabBarSystemItemMore,
UITabBarSystemItemFavorites,
UITabBarSystemItemFeatured,
UITabBarSystemItemTopRated,
UITabBarSystemItemRecents,
UITabBarSystemItemContacts,
UITabBarSystemItemHistory,
UITabBarSystemItemBookmarks,
UITabBarSystemItemSearch,
UITabBarSystemItemDownloads,
UITabBarSystemItemMostRecent,
UITabBarSystemItemMostViewed,
} UITabBarSystemItem;
To set it patientSearch.tabBarItem = aTabBarItem;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With