Last updated on July 31st, 2016 at 11:13 am
In this tutorial, I will show you how create a slide-out (side) menu in iOS application, similar to the one you will see in Facebook or Gmail application . In this post i am using custom library for implementing side menu which is MF SIDEMENU .
Step 1 :
Download library from Github and extract the zipped file. Copy all the classes to your new project .
Classes of MFSideMenu will include (Both .h / .m files) :-
- MFSideMenu
- MFSideMenuContainer
- MFSideMenuShadow
- UIViewController+MFSideMenuAdditions
Add these classes to your new project.
OR
You can add pod 'MFSideMenu'
to your Podfile.
For adding pod
- Open terminal .
- Write cd space DRAG FOLDER TO TERMINAL.
- Write the following command in the terminal .
- pod init // This will initialize the pod.
- open -a Xcode Podfile // This will open the PodTextFile.
- Then add the following code in the text file
pod 'MFSideMenu' .
- Write pod install in the terminal
- Wait for few minutes ,After that Pod installation is been completed.
After pod installation , a workspace is created for your project . Start using workspace instead of the project file .
You can either use pod or can copy files to the Xcode itself.
Step 2 :
Create a new objective -c class which will contain the list of items of side menu.
- Press cmd + n to create a new objective c class and name it SideMenuViewController
- Make the class of type UITableViewController
- Add the following code in .h file of the SideMenuViewController.
- Create a global array which will contain the list of items go the sideMenu.
Step 3:
In the .m file of SideMenuViewController
- Import the MFSideMenu.h
- Add the items in the global array and create a tableView which will hold the list of items of the sideMenu.
- Add tableView`s data source to display data in your menu .
- Code of .m file of SideMenuViewController will look like this :
Step 4:
Go to AppDelegate
- Import ViewController.h and SideMenuViewController.h
- Add the following code to add SideMenuViewController to mainController.(In this controller i am adding SideMenuViewController to)
- Import MFSideMenu.h in AppDelegate.h file.
- Code for AppDelegate.m is this .
Step 5 :
Go to ViewController.m, as i dont want to see navigation bar at this time , I add the following code. You can modify this code accordingly your requirements.
Step 6 :
Swipe Right to see SideMenu in your project.
You can also show SideMenu on button`s click by adding this code in UIButton Action :
[self.menuContainerViewController toggleLeftSideMenuCompletion:^{}];
Thank You 🙂