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.