开发者

Programatic Creation and Config of UITabBarController - Setting a system Image for a tab

开发者 https://www.devze.com 2023-02-05 05:00 出处:网络
Creating a tabBar in an app programatically is fairly easy: self.tabBarController = [[UITabBarController alloc] init];

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消