TabBarController-demo
// // firstViewController.m // TabBarcontroller // // Created by 520 on 15-6-17. // Copyright (c) 2015年 520. All rights reserved. // #import "firstViewController.h" #import "SubViewController.h" @interface firstViewController () @end @implementation firstViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // self.title=@"First"; // self.navigationController.navigationBarHidden=NO; // self.tabBarItem.badgeValue=@"1"; // self.tabBarItem.image=[UIImage imageNamed:@"1.png"]; //self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"1.png"] tag:1];
////创建tabBarItem UIImage *im =[UIImage imageNamed:@"1.png"]; self.tabBarItem.badgeValue=@"37+"; self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:im tag:1]; //self.tabBarController.tabBar.selectedImageTintColor = [UIColor orangeColor]; // [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; // [self.view addSubview:im]; // // self.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1]; // self.tabBarController.tabBar.selectedItem.selectedImage = [UIImage imageNamed:@"1.png"]; // UITabBarItem *t =[[UITabBarItem alloc] initWithTitle:@"first" image:im tag:1]; // self.tabBarItem=t; // self.tabBarItem.image=im } return self; } - (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage{ } - (void)viewDidLoad { [super viewDidLoad];
////每个页面 UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds]; imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例 imageview.image=[UIImage imageNamed:@"011.png"]; [self.view addSubview:imageview]; ////navigationcontroller UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)]; self.navigationItem.rightBarButtonItem=rightBaritem; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)next:(UIBarButtonItem *)barItem{ SubViewController *controller=[[SubViewController alloc] init]; [self.navigationController pushViewController:controller animated:YES]; }
#pargma mark-点击隐藏tabbaritem //// - (void)viewWillAppear:(BOOL)animated{ //[self viewWillAppear:YES]; self.hidesBottomBarWhenPushed=YES; } - (void)viewWillDisappear:(BOOL)animated{ self.hidesBottomBarWhenPushed=NO; } - (void)viewDidDisappear:(BOOL)animated{ //[self viewDidDisappear:YES]; self.hidesBottomBarWhenPushed=NO; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; firstViewController *firstviewcontroller=[[firstViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller]; secondViewController *secondviewcontroller=[[secondViewController alloc] init]; //UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller]; thirdViewController *thirdviewcontroller=[[thirdViewController alloc] init]; //UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller]; fourViewController *fourviewcontroller=[[fourViewController alloc] init]; // UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller]; NSArray *viewcontrollers=[[NSArray alloc] initWithObjects:nav,secondviewcontroller,thirdviewcontroller,fourviewcontroller, nil]; UITabBarController *tabBarcontroller = [[UITabBarController alloc] init]; tabBarcontroller.viewControllers=viewcontrollers; tabBarcontroller.selectedIndex=0; tabBarcontroller.delegate=self; self.window.rootViewController=tabBarcontroller; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"2.png"] tag:2]; // self.tabBarItem.badgeValue=@"37+"; // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds]; imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例 imageview.image=[UIImage imageNamed:@"010.png"]; [self.view addSubview:imageview]; // Do any additional setup after loading the view. }
#pragma mark-响应navigationcontroller
UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)];
self.navigationItem.rightBarButtonItem=rightBaritem;