-3

To preface, I just started iOS programming but do have a rather comprehensive background in Objective-C. So please explain what you are saying, but don't feel like you have to talk like a two year old.

I am building an application that uses a tabbed view controller. I want to move it to the top of the application like Facebook or Ask.fm do with their applications.

I know there have been other articles, but they are kind of old and I don't really understand them. So if you could provide some sample code with your answer that would be great.

All I want to do is move the bar, I don't want to create a new tabbed bar controller or something.

whereisSQL
  • 638
  • 2
  • 13
  • 23
Mark Bourke
  • 9,806
  • 7
  • 26
  • 30

2 Answers2

0

In iOS development, UITabBar is not for the top side. iOS divides each area in different sections, for example UINavigationBar is for top side part not for the footer same as UITabBar can only be use in footer according to Apple's recommendation.

You can use a custom view with the help of UIView and as many UIButtons in it as you want. Let's say you want to create top bar with two button so you can achieve this by doing this:

First, you have to hide UINavigationBar like this:

- (void)viewDidLoad {

    [super viewDidLoad];
    [[self navigationController] setNavigationBarHidden:YES animated:NO];
    _topBar=[self createTopBar];
    [self.View addSubview:_topBar];
}

after that you can create your own custom view like this:

- (UIView *)createTopBar {
    UIView * topBar=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

    UIButton * btnOne=[UIButton buttonWithType:UIButtonTypeCustom];
    btnOne.frame=CGRectMake(0, 5, 34, 34);
    [btnOne setBackgroundColor:[UIColor clearColor]];
    [btnOne addTarget:self action:@selector(YourMethodOne) forControlEvents:UIControlEventTouchUpInside];

    UIButton * btnTwo=[UIButton buttonWithType:UIButtonTypeCustom];
    btnTwo.frame=CGRectMake(270, 5, 34, 34);
    [btnTwo setBackgroundColor:[UIColor clearColor]];
    [btnTwo addTarget:self action:@selector(YourMethodTwo) forControlEvents:UIControlEventTouchUpInside];

    [topBar addSubview:btnOne];
    [topBar addSubview:btnTwo];
}

-(void) YourMethodOne {
    NSLog(@"First button Pressed");
    //Do whatever you want when btnOne is pressed

}

-(void) YourMethodTwo {
    NSLog(@"Second button Pressed");
    //Do whatever you want when btnTwo is pressed

}

In this example I create a local method and a local variable. I prefer to create a proper class and your these button as public instance.

Brian
  • 14,610
  • 7
  • 35
  • 43
AFTAB MUHAMMED KHAN
  • 2,189
  • 3
  • 18
  • 24
0

I am building an application that uses a tabbed view controller. I want to move it to the top of the application like Facebook or Ask.fm do with their applications.

You're confusing UITabBar and UITabBarController, which are entirely different classes. The former is a view, while the latter is a view controller, i.e. not a view at all. Also, perhaps because of that confusion, you're making assumptions about how other apps are implemented. Because the apps you mention put the tabs at the top, it's very unlikely that they use UITabBarController.

All I want to do is move the bar, I don't want to create a new tabbed bar controller or something.

UITabBarController manages an array of other view controllers that you provide, displaying view associated with the currently selected view controller, and it also manages a tab bar. How it lays out the views it manages (tab bar, selected view) is not customizable -- if you want a behavior that's different from what you get with UITabBarController, you need to use a different class.

Caleb
  • 124,013
  • 19
  • 183
  • 272