user2798258
user2798258

Reputation: 171

placing a Tabbar controller on top of viewcontroller

how to connect them. How do i place the TABBAR control on top of view control.by default it is at bottom how do i put it up..?

Used following code to do:

 UIImage* tabBarBackground = [UIImage imageNamed:@"footer-bg.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance]setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];

if(IS_IOS_7)
{
    [[appDelegate.tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];
    [[UITabBar appearance] setTintColor:[UIColor blackColor]];
}
appDelegate.tabBarController.tabBar.frame = CGRectMake(0, 20, 320, 50);
appDelegate.tabBarController.delegate=self;

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, -20, 320, 600)];

viewControllers = [[NSMutableArray alloc] init];

MainViewController *view1 = [[MainViewController alloc] init];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:view1];
[viewControllers addObject:nav1];

ViewController1 *view2 = [[ViewController1 alloc] init];
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:view2];
[viewControllers addObject:nav2];

[appDelegate.tabBarController setViewControllers:viewControllers];

appDelegate.tabBarController.tabBarController.view.frame=CGRectMake(0, 0, 320, 480);
[view addSubview:appDelegate.tabBarController.view];

[self.view addSubview:view];

UITabBarItem *tabBarItem1 = [appDelegate.tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [appDelegate.tabBarController.tabBar.items objectAtIndex:1];


[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:0]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:0]]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:1]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:1]]];

How do i do the same using storyboards?

Upvotes: 0

Views: 6522

Answers (1)

Nicolas Bonnet
Nicolas Bonnet

Reputation: 1274

First add a UIViewController then add the UITabBar and add contraint if you use autolayout.

enter image description here

Don't forgot to connect delegate.

Hope that will help.

Upvotes: 3

Related Questions