Monday, June 10, 2013

UITabBarItem UITabBarSystemItemFavorites example in Objective C (iOS).


UITabBarItem UITabBarSystemItemFavorites

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 UITabBarSystemItemFavorites]
The title and image of system tab bar items cannot be changed.

UITabBarItem UITabBarSystemItemFavorites example.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arraywithObjects: firstViewController, secondViewController, nil]
                            animated:NO];
And to set the tab bar items:

firstViewController.tabBarItem = [UITabBarItem initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
secondViewController.tabBarItem = [UITabBarItem initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1];

Example of [UITabBarItem UITabBarSystemItemFavorites].
        self.title = NSLocalizedString(@"Liked", @"Liked");
        self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
        self.tabBarItem.title = @"Liked";

UITabBarItem UITabBarSystemItemFavorites example.
to hide the above black bar use -

[self.navigationController setNavigationBarHidden:TRUE];
to set tab bar item use -

for system item -

UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
for custom item -

UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@""] tag:0];

[navController setTabBarItem:firstItem];

End of UITabBarItem UITabBarSystemItemFavorites example article.