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 s开发者_开发问答ystem 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;
精彩评论