Simple Custom UITabBarController with UINavigationController in iPhone/iPad programatically

S

//In AppDelegate.h file

UITabBarController *tabBarController;

@property (strong, nonatomic) UITabBarController *tabBarController;

 

//In AppDelegate.h.m file

@synthesize tabBarController = _tabBarController;

 

 

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

 

NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] init];

 

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

 

UIViewController *viewController1 = [[[ViewController1 alloc] initWithNibName:@“ViewController1″ bundle:nil] autorelease];

UIViewController *viewController2 = [[[ViewController2 alloc] initWithNibName:@”ViewController2″ bundle:nil] autorelease];

UIViewController *viewController3 = [[[ViewController3 alloc] initWithNibName:@”ViewController3″ bundle:nil] autorelease];

UIViewController *viewController4 = [[[ViewController4 alloc] initWithNibName:@”ViewController4″ bundle:nil] autorelease];

UIViewController *viewController5 = [[[ViewController5 alloc] initWithNibName:@”ViewController5″ bundle:nil] autorelease];

 

UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];

UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];

UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];

UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:viewController5];

 

navigationController1.navigationBar.barStyle = UIBarStyleDefault;

navigationController2.navigationBar.barStyle = UIBarStyleDefault;

navigationController3.navigationBar.barStyle = UIBarStyleDefault;

navigationController4.navigationBar.barStyle = UIBarStyleDefault;

navigationController5.navigationBar.barStyle = UIBarStyleDefault;

 

navigationController1.navigationBar.tintColor = [UIColor whiteColor];

navigationController2.navigationBar.tintColor = [UIColor blackColor];

navigationController3.navigationBar.tintColor = [UIColor blackColor];

navigationController4.navigationBar.tintColor = [UIColor blackColor];

navigationController5.navigationBar.tintColor = [UIColor blackColor];

 

navigationController4.navigationItem.hidesBackButton = YES;

 

//viewController1.title = @”ViewController1″;

viewController2.title = @”ViewController2″;

viewController3.title = @”ViewController3″;

viewController4.title = @”ViewController4″;

viewController5.title = @”ViewController5″;

 

[tabBarViewControllers addObject:navigationController1];

[tabBarViewControllers addObject:navigationController2];

[tabBarViewControllers addObject:navigationController3];

[tabBarViewControllers addObject:navigationController4];

[tabBarViewControllers addObject:navigationController5];

 

self.tabBarController.viewControllers = tabBarViewControllers;

 

self.window.rootViewController = self.tabBarController;

 

[self.window makeKeyAndVisible];

 

About the author

surjit.joshi
By surjit.joshi

Category