Hi,In this tutorial I want to create custom top menu bar that when press in any menu item show different view controller with objective-c in iOS.
1-in first step we should add The number of buttons that needed in menu to main view controller.In the below image you can see this step adjective:
And then Drag & Drop any button to main view controller and create outlet and action for any of the buttons.
2-in this step we should add a container view to main view controller As shown below:
then create outlet from container view to main view controller.
3-in this step we should add view controller the number of menu item in above steps to our storyboard As shown below:
then create class .h and .m for any view controller and connect view contrllers to own class.then we must assign unique Storyboard ID for each of Item view controllers as shown below:
4-after we do above steps we should add view controllers classes to our main view controller with #import
5-in this step we must create an instance from any of view controllers inside of own item button action and set size of view controller in container view.
In the below you can see code of this step:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; Item1ViewController *MenuItem1 = [storyboard instantiateViewControllerWithIdentifier:@"Item1ViewController"]; [self addChildViewController:MenuItem1]; MenuItem1.view.frame = CGRectMake(0, 0, self.ContainerView.frame.size.width, self.ContainerView.frame.size.height); [self.ContainerView addSubview:MenuItem1.view]; [MenuItem1 didMoveToParentViewController:self];
At the End of this tutorial you can Download source code.
I hope this tutorial is useful for you.