You are very mistaken. Do not create your own view hierarchy if you can just use it by default.
What you want to do is create a subclass of UITabBarController and also create a .xib file that will contain your own tab bar - just an image and an arbitrary number of UIButtons (I assume 5).

Set tags for all of them, just 1-5 tags, you can do it with a custom subclass of UIView , but that will be superfluous in this scenario, so it will just be a selection of controls using tags.
Create a subclass of UITabBarController . You will need links to all of these buttons, as well as a property, to see which button was last pressed so that you can update the interface accordingly. Also assign different images or captions for different control states, I use the default and selected in this case.
MYBaseTabBarController.h
@interface MYBaseTabBarController : UITabBarController @property (strong, nonatomic) UIButton *btn1; @property (strong, nonatomic) UIButton *btn2; @property (strong, nonatomic) UIButton *btn3; @property (strong, nonatomic) UIButton *btn4; @property (strong, nonatomic) UIButton *btn5; @property (weak, nonatomic) UIButton *lastSender; @property (strong, nonatomic) UIView *tabBarView; @end
MYBaseTabBarController.m
First of all, create view controllers (which in this case are subclasses of UINavigationController ) and assign them to your subclass UITabBarController as a property of viewControllers .
- (id)init { self = [super init]; if (self) { [self setup]; } return self; } - (void)setup { NSMutableArray *viewControllers = [NSMutableArray array]; MYViewController1 *viewController1 = [[MYStoryboardManager storyboard1] instantiateInitialViewController]; viewController1.title = @"1"; [viewControllers addObject:viewController1]; MYViewController2 *viewController2 = [[MYStoryboardManager storyboard2] instantiateInitialViewController]; viewController2.title = @"2"; [viewControllers addObject:viewController2]; UIViewController *blankController = [UIViewController new];
Then take the buttons you created earlier and assign them actions in the -viewDidLoad method:
- (void)viewDidLoad { [super viewDidLoad]; _tabbarView = [[[NSBundle mainBundle] loadNibNamed:@"MyTabBar" owner:nil options:nil] lastObject]; // "MyTabBar" is the name of the .xib file _tabbarView.frame = CGRectMake(0.0, self.view.frame.size.height - _tabbarView.frame.size.height, _tabbarView.frame.size.width, _tabbarView.frame.size.height); // make it overlay your actual tab bar [self.view addSubview:_tabbarView]; _btn1 = (UIButton *)[_tabbarView viewWithTag:1]; [_btn1 addTarget:self action:@selector(processBtn:) forControlEvents:UIControlEventTouchUpInside]; _btn2 = (UIButton *)[_tabbarView viewWithTag:2]; [_btn2 addTarget:self action:@selector(processBtn:) forControlEvents:UIControlEventTouchUpInside]; _btn3 = (UIButton *)[_tabbarView viewWithTag:3]; [_btn3 addTarget:self action:@selector(processBtn:) forControlEvents:UIControlEventTouchUpInside]; _btn4 = (UIButton *)[_tabbarView viewWithTag:4]; [_btn4 addTarget:self action:@selector(processBtn:) forControlEvents:UIControlEventTouchUpInside]; _btn5 = (UIButton *)[_tabbarView viewWithTag:5]; [_btn5 addTarget:self action:@selector(processBtn:) forControlEvents:UIControlEventTouchUpInside]; _lastSender = _btn1; [self setSelectedViewController:self.viewControllers[0]]; // make first controller selected }
Add a processing method:
- (void)processBtn:(UIButton *)sender { _lastSender = sender; [self setSelectedViewController:[self.viewControllers objectAtIndex:sender.tag - 1]]; }
Finally, override the -setSelectedViewController: method:
- (void)setSelectedViewController:(UIViewController *)selectedViewController { if (_lastSender != _btn3) { // check if it not the action button for (UIButton *btn in [_tabbarView subviews]) { if ([btn isKindOfClass:[UIButton class]]) { if (btn == _lastSender) { btn.selected = YES; } else { btn.selected = NO; } } } } if ([self.viewControllers indexOfObject:selectedViewController] == 2) { MYActionController *viewController = [[MYStoryboardManager actionStoryboard] instantiateInitialViewController]; [self presentViewController:viewController animated:YES completion:nil]; } else { if (self.selectedViewController == selectedViewController) { [(UINavigationController *)self.selectedViewController popToRootViewControllerAnimated:animate]; // pop to root if tapped the same controller twice } [super setSelectedViewController:selectedViewController]; } }
I assume that you are programming with ARC enabled and that you have a class that manages your storyboards, but in any case it's pretty simple.