Monday, June 10, 2013

UITabBarItem UITabBarSystemItemMore example in Objective C (iOS).


UITabBarItem UITabBarSystemItemMore

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;

Constants
UITabBarSystemItemMore
The more system item.
UITabBarSystemItemFavorites
The favorites system item.
UITabBarSystemItemFeatured
The featured system item.
UITabBarSystemItemTopRated
The top rated system item.
UITabBarSystemItemRecents
The recents system item.
UITabBarSystemItemContacts
The contacts system item.
UITabBarSystemItemHistory
The history system item.
UITabBarSystemItemBookmarks
The bookmarks system item.
UITabBarSystemItemSearch
The search system item.
UITabBarSystemItemDownloads
The downloads system item.
UITabBarSystemItemMostRecent
The most recent system item.
UITabBarSystemItemMostViewed
The most viewed system item.

Discussion of [UITabBarItem UITabBarSystemItemMore]
The title and image of system tab bar items cannot be changed.

UITabBarItem UITabBarSystemItemMore example.
UITabBarItem *barItem = [[UITabBarItem] alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:0];
self.tabBarItem = [barItem autorelease]; //of not using ARC

Example of [UITabBarItem UITabBarSystemItemMore].
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];

    // Initialize view controllers
    HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    ConnectViewController *connectViewController = [[ConnectViewController alloc] initWithNibName:@"ConnectViewController" bundle:nil];
    PartyControlViewController *partyControlViewController = [[PartyControlViewController alloc] initWithNibName:@"PartyControlViewController" bundle:nil];
    MeViewController *meViewController = [[MeViewController alloc] initWithNibName:@"MeViewController" bundle:nil];
    MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];

    [self.tabBarController setViewControllers:[NSArray arrayWithObjects:homeViewController, connectViewController, partyControlViewController, meViewController, moreViewController, nil]];

    // Customize Tab Bar
    UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:@"Home" image:nil tag:0];
    UITabBarItem *connectTab = [[UITabBarItem alloc] initWithTitle:@"Connect" image:nil tag:1];
    UITabBarItem *partyControlTab = [[UITabBarItem alloc] initWithTitle:@"Party Control" image:nil tag:2];
    UITabBarItem *meTab = [[UITabBarItem alloc] initWithTitle:@"Me" image:[UIImage imageNamed:@"person.png"] tag:3];
    UITabBarItem *moreTab = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];

    [homeViewController setTabBarItem:homeTab];
    [connectViewController setTabBarItem:connectTab];
    [partyControlViewController setTabBarItem:partyControlTab];
    [meViewController setTabBarItem:meTab];
    [moreViewController setTabBarItem:moreTab];

    self.window.rootViewController = self.tabBarController;
}

UITabBarItem UITabBarSystemItemMore example.
- (void)setNewItems {
    UITabBarItem *featured = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0]; featured.badgeValue = @"1";
    UITabBarItem *mostViewed = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
    UITabBarItem *search = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:2];
    UITabBarItem *favorites = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:3];
    UITabBarItem *more = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];

    [self.tabBar setItems:[NSArray arrayWithObjects:featured,
                           mostViewed,
                           search,
                           favorites,
                           more, nil] animated:NO];

}

End of UITabBarItem UITabBarSystemItemMore example article.