2011-01-14 9 views
5

Erstellen eines tabBar in einer App programmatisch ein System Bild für eine Registerkarte Einstellung ziemlich einfach:programatic Erstellung und Konfiguration von UITabBarController - ist

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]; 

können Sie auch Bilder einfach in den Registerkarten setzen:

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

Wie kann ich jedoch das Bild dieser Registerkarten auf eines der Systembilder einstellen? (z. B. Suche, Favoriten, Lesezeichen etc.) In IB dies durch eine Änderung der 'Bezeichner' gesetzt ist, aber wie kann man tun, um diese programmatisch

Antwort

10
UITabBarItem *aTabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0]; 

UITabBarItem docs

UITabBarSystemItem System-Elemente, die kann in einer Tab-Leiste verwendet werden.

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

Zum Einstellen patientSearch.tabBarItem = aTabBarItem;

+0

was die Verwendung Fall von 'tag' ist? – Honey

Verwandte Themen