TKSideDrawer: SideDrawer with UINavigationController

Sometimes, you may want to use UINavigationController to navigate in your app and also have a TKSideDrawer that slides on top of it. Such scenario can be achieved easily using TKSideDrawerController. TKSideDrawerController is a content controller that will present your UINavigationController and also has a sideDrawer property which is accessible from every UIViewController you push in the stack. To set up the TKSideDrawerController, open your AppDelegate and paste the code below inside application:didFinishLaunchingWithOptions:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    //For the SideDrawer GettingStarted
    SideDrawerGettingStarted *main = [[SideDrawerGettingStarted alloc] init];
    TKSideDrawerController *sideDrawerController = [[TKSideDrawerController alloc] initWithContent:main];
    [self.window setRootViewController:sideDrawerController];

    return YES;
}

//..
@end
class AppDelegate: UIResponder, UIApplicationDelegate {

   var window: UIWindow?

   @nonobjc func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
   // Override point for customization after application launch.

       let sideDrawerGettingStarted = SideDrawerGettingStartedViewController()
       let sideDrawerController = TKSideDrawerController(content: sideDrawerGettingStarted)
       self.window?.rootViewController = sideDrawerController

       return true
   }

//..
}
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
    // class-level declarations

    public override UIWindow Window {
        get;
        set;
    }

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        SideDrawerGettingStarted main = new SideDrawerGettingStarted ();
        TKSideDrawerController sideDrawerController = new TKSideDrawerController (main);
        this.Window.RootViewController = sideDrawerController;

        return true;
    }

    //..
}

In this example, SideDrawerGettingStarted is a UIViewController subclass which is the initially displayed controller by the UINavigationController. From there on you can set up the side drawer inside the SideDrawerController's viewDidLoad:

@implementation SideDrawerGettingStarted
{
}

- (void)viewDidLoad {
[super viewDidLoad];

   self.view.backgroundColor = [UIColor grayColor];

   UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
   UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Getting Started"];
   UIBarButtonItem *showSideDrawerButton = [[UIBarButtonItem alloc] initWithTitle:@"Show"  style:UIBarButtonItemStylePlain target:self action:@selector(showSideDrawer)];
   navItem.leftBarButtonItem = showSideDrawerButton;
   navBar.items = @[navItem];
   [self.view addSubview:navBar];

   TKSideDrawerSection *sectionPrimary = [self.sideDrawer addSectionWithTitle:@"Primary"];
   [sectionPrimary addItemWithTitle:@"Social"];
   [sectionPrimary addItemWithTitle:@"Promotions"];

   TKSideDrawerSection *sectionLabels = [self.sideDrawer addSectionWithTitle:@"Labels"];
   [sectionLabels addItemWithTitle:@"Important"];
   [sectionLabels addItemWithTitle:@"Starred"];
   [sectionLabels addItemWithTitle:@"Sent Mail"];
   [sectionLabels addItemWithTitle:@"Drafts"];
}

- (void)showSideDrawer
{
   [self.sideDrawer show];
}

@end
class SideDrawerGettingStartedViewController: UIViewController {

   override func viewDidLoad() {
       super.viewDidLoad()

       self.view.backgroundColor = UIColor.gray

       let navBar = UINavigationBar(frame: CGRect.init(x:0, y:0, width:self.view.frame.size.width, height:64))
       let navItem = UINavigationItem(title: "Getting Started")
       let showSideDrawerButton = UIBarButtonItem(title: "Show", style: UIBarButtonItemStyle.plain, target: self, action: #selector(showSideDrawer))
       navItem.leftBarButtonItem = showSideDrawerButton
       navBar.items = [navItem]
       self.view.addSubview(navBar)

       let sectionPrimary = self.sideDrawer.addSection(withTitle: "Primary")
        _ = sectionPrimary?.addItem(withTitle: "Social")
        _ = sectionPrimary?.addItem(withTitle: "Promotions")

       let sectionLabels = self.sideDrawer.addSection(withTitle: "Primary")
        _ = sectionLabels?.addItem(withTitle: "Social")
        _ = sectionLabels?.addItem(withTitle: "Promotions")
        _ = sectionLabels?.addItem(withTitle: "Sent Mail")
        _ = sectionLabels?.addItem(withTitle: "Drafts")
   }

   func showSideDrawer() {
       self.sideDrawer.show()
   }

}
public class SideDrawerGettingStarted : UIViewController
{
    TKSideDrawer SideDrawer;

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        this.View.BackgroundColor = UIColor.Gray;

        UINavigationBar navBar = new UINavigationBar (new CGRect (0, 0, this.View.Frame.Size.Width, 64));
        UINavigationItem navItem = new UINavigationItem ("Getting Started");
        UIBarButtonItem showSideDrawerButton = new UIBarButtonItem ("Show", UIBarButtonItemStyle.Plain, this, new Selector ("ShowSideDrawer"));
        navItem.LeftBarButtonItem = showSideDrawerButton;
        navBar.Items = new UINavigationItem[]{ navItem };
        this.View.AddSubview (navBar);

        this.SideDrawer = TKSideDrawer.FindSideDrawer (0, this);
        TKSideDrawerSection sectionPrimary = this.SideDrawer.AddSection ("Primary");
        sectionPrimary.AddItem ("Social");
        sectionPrimary.AddItem ("Promotions");

        TKSideDrawerSection sectionLabels = this.SideDrawer.AddSection ("Labels");
        sectionLabels.AddItem ("Important");
        sectionLabels.AddItem ("Starred");
        sectionLabels.AddItem ("Sent Mail");
        sectionLabels.AddItem ("Drafts");
    }

    [Export ("ShowSideDrawer")]
    public void ShowSideDrawer ()
    {
        this.SideDrawer.Show ();
    }
}