Combination of iOS navigation controller and tag bar Controller

Source: Internet
Author: User

Combination of iOS navigation controller and tag bar Controller

-(Void) initTabBar {// initialize the Home Page HomePageViewController * homePage = [[HomePageViewController alloc] init]; UINavigationController * handle = [[UINavigationController alloc] handle: homePage]; // determine whether the city in which the user stores NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults]; if (! [UserDefault objectForKey: @ "cityDic"]) {CitySelectionViewController * citySelection = [[CitySelectionViewController alloc] init]; [homePageNav pushViewController: citySelection animated: YES];} // set homepage-TabBar UITabBarItem * itemHomePage = [[UITabBarItem alloc] initWithTitle: @ "Homepage" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemHomePage usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; homePageNav. tabBarItem = itemHomePage; [itemHomePage failed: [NSDictionary failed: NAVBACKGROUNDCOLOR, failed, nil] forState: UIControlStateSelected]; if (failed ([NSString stringWithFormat: @ "7.0"]) {[homePageNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[homePageNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} homePageNav. navigationBar. translucent = NO; // initialize my shopping carshoppingcartviewcontroller * shoppingCart = [[ShoppingCartViewController alloc] init]; UINavigationController * handle = [[UINavigationController alloc] handle: shoppingCart]; // set shopping cart-TabBar UITabBarItem * items = [[UITabBarItem alloc] initWithTitle: @ "my shopping cart" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemShoppingCart handle: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] labels: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; shoppingCartNav. tabBarItem = itemShoppingCart; [itemShoppingCart attributes: [NSDictionary attributes: NAVBACKGROUNDCOLOR, attributes, nil] forState: UIControlStateSelected]; if (attributes ([NSString stringWithFormat: @ "7.0"]) {[shoppingCartNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[shoppingCartNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} shoppingCartNav. navigationBar. translucent = NO; // initialize our consumer * individualCenter = [[Alibaba alloc] init]; UINavigationController * handle = [[UINavigationController alloc] initWithRootViewController: individualCenter]; // set huizhong-TabBar UITabBarItem * region = [[UITabBarItem alloc] initWithTitle: @ "My happy home" image: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.png"] scaledToSize: CGSizeMake (25, 25)] tag: 0]; [itemindividualCenter usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-1.jpg"] scaledToSize: CGSizeMake (25, 25)] usage: [UIImage imageWithImage: [UIImage imageNamed: @ "1-2.jpg"] scaledToSize: CGSizeMake (25, 25)]; individualCenterNav. tabBarItem = itemindividualCenter; [itemindividualCenter feature: [NSDictionary feature: NAVBACKGROUNDCOLOR, rule, nil] forState: UIControlStateSelected]; if (feature ([NSString stringWithFormat: @ "7.0"]) {[individualCenterNav. navigationBar setBarTintColor: NAVBACKGROUNDCOLOR];} else {[individualCenterNav. navigationBar setTintColor: NAVBACKGROUNDCOLOR];} individualCenterNav. navigationBar. translucent = NO; self. tabBar = [[UITabBarController alloc] init]; [[UITabBar appearance] setBackgroundImage: [UIImage layout: COLOR (255,255,255, 1) withFrame: RectWithPara (0, 0, SCREEN_WIDTH, 44)]; // set the UITabBar background image [[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageWithTint: COLOR (235,235,235, 1)]; self. tabBar. viewControllers = [NSArray arrayWithObjects: homePageNav, shoppingCartNav, individualCenterNav, nil];}


Set the root controller to tabbar when the program starts, as shown below:

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions

{

Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen] bounds];


[SelfinitTabBar];

Self. window. rootViewController = self. tabBar;

Self. window. backgroundColor = [UIColorwhiteColor];

[Self. windowmakeKeyAndVisible];

Return YES;

}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.