2011-01-14 5 views
5

Tworzenie umieszczenie zakładek w aplikacji programowo jest dość proste:Zautomatyzowane tworzenie i Config UITabBarController - Ustawianie obrazu systemu na karcie

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

Można również łatwo umieścić obrazy w zakładkach:

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

Jak jednak ustawić obraz tych zakładek na jeden z obrazów systemu? (np. Wyszukiwanie, ulubione, zakładki itp) w IB jest ustawiony poprzez zmianę 'identyfikator', ale w jaki sposób można to zrobić programowo

Odpowiedz

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

UITabBarItem docs

UITabBarSystemItem elementy systemu, który można użyć na pasku kart.

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

ustawić go patientSearch.tabBarItem = aTabBarItem;

+0

co jest w przypadku stosowanie 'tag'? – Honey

Powiązane problemy