TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Josh Holtz.
Probably just another sidebar library but this is the way I wanted them implemented.
#import <JHSidebar/JHSidebarViewController.h>
Clone the repository and drop in the .h and .m files from the "Classes" directory into your project.
- (void)onClickLeft:(id)sender {
// Open left sidebar
[self.sidebarViewController showLeftSidebar:YES];
// Close left sidebar
[self.sidebarViewController showLeftSidebar:NO];
// Toggle left sidebar
[self.sidebarViewController toggleLeftSidebar];
}
- (void)onClickRight:(id)sender {
// Open right sidebar
[self.sidebarViewController showRightSidebar:YES];
// Close right sidebar
[self.sidebarViewController showRightSidebar:NO];
// Toggle right sidebar
[self.sidebarViewController toggleRightSidebar];
}
The main view, left sidebar, and right sidebar can be set up by naming scenes with the following default identifiers.
These are the default identifiers used to instantiate these view controllers from the Storyboard. If you'd like to override them or not use one you can override the following methods.
- (UIViewController *)instantiateMainViewController; // override
- (UIViewController *)instantiateLeftViewController; // override
- (UIViewController *)instantiateRightViewController; // override
Either return a view controller or nil.
If storyboards are not the route you want to take, you can initialize the JHSidebarViewController directly in your code by setting setting the main view controller and both, one, or none of the left and right sidebar view controllers.
AppDelegate.h
#import <UIKit/UIKit.h>
@class JHSidebarViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) JHSidebarViewController *sidebarViewController;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "LeftViewController.h"
#import "RightViewController.h"
#import <JHSidebar/JHSidebarViewController.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
// Initializes JHSidebarViewController
self.sidebarViewController = [[JHSidebarViewController alloc] init];
[self.sidebarViewController enableTapGesture]; // Enables tap on open sidebar to close
[self.sidebarViewController enablePanGesture]; // Enables panning to open and close sidebars
[self.sidebarViewController setSlideMainViewWithLeftSidebar:YES]; // Main view will slide with side bar instead of left side bar overlapping main view
[self.sidebarViewController setRightSidebarWidth:220.0f]; // Sets width of right sidebar
// Sets "main view"
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.sidebarViewController.mainViewController = navController;
// Sets "left sidebar"
self.sidebarViewController.leftViewController = [[LeftViewController alloc] initWithNibName:@"LeftViewController" bundle:[NSBundle mainBundle]];
// Sets "right sidebar"
self.sidebarViewController.rightViewController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:[NSBundle mainBundle]];
self.window.rootViewController = self.sidebarViewController;
return YES;
}
@end
Josh Holtz, [email protected], @joshdholtz
JHSidebar is available under the MIT license. See the LICENSE file for more info.