TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Scott Berrevoets.
SBSegmentedViewController
is a custom view controller container that uses a segmented control to switch between view controllers. It can be used with iOS 5.0+, though the deployment target for the sample project is set to iOS 6.0.
SBSegmentedViewController
is very easy to use, and can be set up either using a storyboard or programmatically. It sets up a container view controller that switches between its child view controllers with a UISegmentedControl
. The segmented control can be placed in either the navigation bar or the toolbar of the navigation controller that contains SBSegmentedViewController
. This position can be set using the position
property (for which the options are SBSegmentedViewControllerPositionNavigationBar
or SBSegmentedViewControllerPositionToolbar
).
Follow these steps to instantiate SBSegmentedViewController
from a storyboard:
SBSegmentedViewController
SBSegmentedViewController
in a navigation controllerSBSegmentedViewController
title
properties in the storyboard. This is a requirement, as the title attribute is used for setting the segment's title.SBSegmentedViewController
scene to a view controller that you created in step 2-[SBSegmentedViewController addStoryboardSegments:]
passing in an NSArray
of NSString
s that match the segue identifiersThe code below is a sample use of SBSegmentedViewController
in application:didFinishLaunchingWithOptions:
when created programmatically:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MyViewController *myVC1 = [[MyViewController alloc] initWithNibName:@"MyVC1" bundle:nil];
MyOtherViewController *myVC2 = [[MyViewController alloc] initWithNibName:@"MyVC2" bundle:nil];
SBSegmentedViewController *segmentedController = [[SBSegmentedViewController alloc] initWithViewControllers:@[myVC1, myVC2]];
// Or, we could choose our own titles:
// SBSegmentedViewController *segmentedController = [[SBSegmentedViewController alloc] initWithViewControllers:@[myVC1, myVC2] titles:@[@"Segment 1", @"Segment 2"]];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:segmentedController];
[self.window makeKeyAndVisible];
}
Of course you don't have to use SBSegmentedViewController
as the root view controller, you can push it onto a navigation controller, present it modally, or do anything else that you can do with a normal view controller.
The MIT license applies to the code distributed in this repo.