Create Left/Right/Both Slider Menus In Your App With Objective C

I will provide you with some steps to create left/right/both slider menus in your app with Objective C. You can simply Download and use it in your project.

Here are the steps:

  • Open Xcode.
  • Click on Create a new Xcode project.
  • Now select Single View Application.
  • Click -> Next.
  • Enter -> Product Name and Other blank fields (if any).

Now select the location where you want to save your project and click on Create.

Now Download the files from top and open it.

Drag these files in your project

Must For Sliding operation:

  1. SWRevealViewController.h

  2. SWRevealViewController.m
For Left slider operation:
  1. NavigationViewController.h

  2. NavigationViewController.m
For Right slider operation:
  1. RightViewController.h

  2. RightViewController.m
For Images:
  1. menu1.png

  2. leftMenu.jpg

  3. rightMenu.jpg

Now you will get a prompt to Choose options for adding these files.

Make sure these are selected:

  1. Copy items if needed.
  2. Create folder references.
  3. Add to targets: Name of your project (first one).

Click -> Finish.

Write/copy the following code in ViewController.h.

  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface ViewController : UIViewController  
  4.   
  5. @property (weak, nonatomic) IBOutlet UIBarButtonItem *Leftbarbutton;  
  6. @property (weak, nonatomic) IBOutlet UIBarButtonItem *Rightbarbutton;  
  7.   
  8. @end  
Same with ViewController.m
  1. #import "ViewController.h"#  
  2. import "SWRevealViewController.h"@  
  3. interface ViewController()@ end@ implementation ViewController - (void) viewDidLoad  
  4. {  
  5.     [super viewDidLoad];  
  6.     // Do any additional setup after loading the view, typically from a nib.  
  7.     // To Set Title on Navigation/Top Bar  
  8.     self.title = @"Welcome";  
  9.     //Left slidebutton  
  10.     _Leftbarbutton.target = self.revealViewController;  
  11.     _Leftbarbutton.action = @selector(revealToggle: );  
  12.     // For Pan gesture(Left Side)  
  13.     [self.view addGestureRecognizer: self.revealViewController.panGestureRecognizer];  
  14.     //Right slidebutton  
  15.     _Rightbarbutton.target = self.revealViewController;  
  16.     _Rightbarbutton.action = @selector(rightRevealToggle: );  
  17.     // For Pan gesture(Right Side)  
  18.     [self.view addGestureRecognizer: self.revealViewController.panGestureRecognizer];  
  19. } - (void) didReceiveMemoryWarning  
  20. {  
  21.     [super didReceiveMemoryWarning];  
  22.     // Dispose of any resources that can be recreated.  
  23. }@  
  24. end  
Now in Main.storyboard: 
  1. Change the class name of initial View Controller to SWRevealViewController.

    SWRevealViewController

  2. Add a new Table View Controller and change its class name to NavigationViewController.



  3. Now make number of Prototype Cells to your desire cell number[Change “menu” array in .m file of respective class according to no. of cells which is 9 in my case].

  4. You can change Table View Style to "Grouped".

  5. Now click on each cell one by one and change style to “Basic” and set Identifier to “one”,”two”,”three”, and so on till last cell.

    style

  6. Add a Navigation Controller and Delete TableView Controller comes along with Navigation Controller.

  7. Now add a View Controller and set its class name to ViewController.

  8. Now set Connection of SWRevealViewController (refers to point 1) with NavigationViewController(refers to point 2) by selecting reveal view controller.

  9. Set segue Identifier as “sw_rear”.

    sw_rear

  10. In the same way connect SWRevealViewController with Navigation Controller (refer to point 6) by selecting reveal view controller.

  11. Set segue Identifier as “sw_front”.

  12. Now connect Navigation Controller (refers to point 6) with View Controller (refers to point 7) by Relationship Segue -> rootviewcontroller.

  13. Add Bar Button Item to Navigation bar on View Controller and set image name “menu1.png”.

  14. Now set Properties of Button which we declared earlier in ViewController.h.

    Left Side Slider Menu Is Ready To Use.

    Note: Change the Text Colour of each cell to White Colour by clicking on text on cell each one by one for better visuals.

  15. Here are some additional steps to follow for right side Slider Menu:

  16. Repeat Step 14 & 15 for right side Button (You can use same image here also).

  17. Add a new Table View Controller and change its class name to RightViewController.

  18. Repeat Steps 3, 4 & 5.

  19. Set Connection of SWRevealViewController (refers to point 1) with RightViewController (refers to point 17) by selecting reveal view controller.

  20. Set segue Identifier as “sw_right”.

Note 1: Change the Text Colour of each cell to White Colour by clicking on text on cell each one by one for better visuals.

Note 2: You can change Sliders background images by replacing images with same name (No Need To Change Coding).