SideMenu
Simple side/slide menu control for iOS, no code necessary! Lots of customization. Add it to your project in 5 minutes or less.
SideMenu is a simple and versatile side menu control written in Swift.
- [x] It can be implemented in storyboard without a single line of code.
- [x] Four standard animation styles to choose from (there's even a parallax effect if you want to get weird).
- [x] Highly customizable without needing to write tons of custom code.
- [x] Supports continuous swiping between side menus on boths sides in a single gesture.
- [x] Global menu configuration. Set-up once and be done for all screens.
- [x] Menus can be presented and dismissed the same as any other view controller since this control uses custom transitions.
- [x] Animations use your view controllers, not snapshots.
- [x] Properly handles screen rotation and in-call status bar height changes.
Check out the example project to see it in action!
Preview Samples
Slide Out | Slide In | Dissolve | Slide In + Out |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Requirements
- [x] Xcode 10.
- [x] Swift 4.2.
- [x] iOS 10 or higher.
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
To integrate SideMenu into your Xcode project using CocoaPods, specify it in your Podfile
:
Then, run the following command:
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
To integrate SideMenu into your Xcode project using Carthage, specify it in your Cartfile
:
Usage
Code-less Storyboard Implementation
-
Create a Navigation Controller for a side menu. Set the
Custom Class
of the Navigation Controller to beUISideMenuNavigationController
in the Identity Inspector. Set theModule
toSideMenu
(ignore this step if you've manually added SideMenu to your project). Create a Root View Controller for the Navigation Controller (shown as a UITableViewController below). Set up any Triggered Segues you want in that view controller.
-
Set the
Left Side
property of theUISideMenuNavigationController
to On if you want it to appear from the left side of the screen, or Off/Default if you want it to appear from the right side.
-
Add a UIButton or UIBarButton to a view controller that you want to display the menu from. Set that button's Triggered Segues action to modally present the Navigation Controller from step 1.
That's it. Note: you can only enable gestures in code.
Code Implementation
First:
In your view controller's viewDidLoad
event, do something like this (IMPORTANT: If you're seeing a black menu when you use gestures, read this section carefully!):
Then from a button, do something like this:
To dismiss a menu programmatically, do something like this:
That's it.
Customization
SideMenuManager
Just type SideMenuManager.default.menu...
and code completion will show you everything you can customize (for Objective-C, use SideMenuManager.defaultManager.menu...
). Defaults values are shown below for reference:
UISideMenuNavigationController
UISideMenuNavigationController
supports the following customizations and properties:
UISideMenuNavigationControllerDelegate
To receive notifications when a menu is displayed from a view controller, have it adhere to the UISideMenuNavigationControllerDelegate
protocol:
Note: setting the sideMenuDelegate
property on UISideMenuNavigationController
is optional. If your view controller adheres to the protocol then the methods will be called automatically.
Advanced
For simplicity, SideMenuManager.default
serves as the primary instance as most projects will only need one menu across all screens. If you need to show a different SideMenu, such as from a modal view controller presented from a previous SideMenu, do the following:
- Declare a variable containing your custom
SideMenuManager
instance. You may want it to define it globally and configure it in your app delegate if menus will be used on multiple screens.
- Setup and display menus with your custom instance the same as you would with the
SideMenuManager.default
instance. - If using Storyboards, subclass your instance of
UISideMenuNavigationController
and set itssideMenuManager
property to your custom instance. This must be done beforeviewDidLoad
is called:
Alternatively, you can set sideMenuManager
from the view controller that segues to your UISideMenuNavigationController:
Important: displaying SideMenu instances directly over each other is not supported. Use menuPushStyle = .subMenu
instead.