Skip to content

Custom Storyboard UITabbarController / UINavigationController

License

Notifications You must be signed in to change notification settings

iosdec/SBTabbarController

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SBTabbarController

Storyboard based UITabBarController.

Want to create a custom UITabBarController from the interface builder? Here is your solution.

Installation:

Drag these files into your project:

"SBTabbarController.m"
"SBTabbarController.h"

Then import the header into your project where needed:

#import "SBTabbarController.h"

Setup:

For SBTabbarController to function, create a UIViewController in the interface builder; in this you will create your navigation system (I'm going to use a sidebar as an example):

Controller Setup

"Active View"

We need to create an active view in the controller.. when we change tabs or push controllers onto the stack, this is where they will be displayed - so feel free to customise the frame.

All we have to do, is set the Restoration ID of this view to "SBTabbarController":

Restoration ID Setup

Initialise:

Now we have our controller setup, we just need to initialise a SBTabbarController instance and set the controllers.

We will simply create a UIViewController class for our custom controller:

Custom Class Setup

Now in our custom class.. we can setup our SBTabbarController:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTabbarController];
}

#pragma mark	-	Custom Tabbar controller setup:

- (void)setupTabbarController {
	
    SBTabbarController *tabBar	=	[[SBTabbarController alloc] initWithController:self];
    
    UIViewController *first		=	[UIViewController new];
    UIViewController *second	=	[UIViewController new];
    UIViewController *third		=	[UIViewController new];
    UIViewController *fourth	=	[UIViewController new];
    
    NSArray *controllers		=	@[first, second, third, fourth];
    [tabBar setTabbarControllers:controllers];
	
}

Usage:

Let's say that we've setup custom actions for our example buttons (tab1, tab2, etc) - when we click these 'tabs', we want to change to a tab in the controllers that we set. Easily done.

- (IBAction *)changeToTab1 {
	[[SBTabbarController sharedInstance] changeTab:0];
}
- (IBAction *)changeToTab2 {
	[[SBTabbarController sharedInstance] changeTab:1];
}

Navigation stack:

SBTabbarController also supports a navigation stack - using the same "active" view.
Similar methods to UINavigationController have been created:

Push
- (IBAction *)toToNextScreen {
    UIViewController *nextController = [UIViewController new];
    [[SBTabbarController sharedInstance] pushViewController:nextController];
}
Pop
- (IBAction *)goBack {
	[[SBTabbarController sharedInstance] popViewController];
}
Replace
- (IBAction *)replaceScreen {
	UIViewController *replacement = [UIViewController new];
    [[SBTabbarController sharedInstance] replaceViewController:replacement animated:YES];
}
Unwind
- (IBAction *)unwindNavigationStack {
	[[SBTabbarController sharedInstance] 0];
}

## Credits:

iOSDec

Releases

No releases published

Packages

No packages published