An interactive iOS side menu with rich features.
SideMenu is an easy-to-use side menu container controller written in Swift 5.
Besides all the features a Side Menu should have, it supports:
Menu Position / Status Menu Behavior
Above + None | Below + Slide |
---|---|
![]() |
![]() |
SideBySide + Fade | SideBySide + HideOnMenu |
---|---|
![]() |
![]() |
We call the left/right view controller as the menu view controller, the central view controller as content view controller.
For Swift 5.0 and later, please use 2.0.0 or later version.
To install SideMenu
with CocoaPods, add the below line in your Podfile
:
pod 'SideMenuSwift'
# Note it's NOT 'SideMenu'
To install SideMenu
with Carthage, add the below line in your Cartfile
:
github "kukushi/SideMenu" "master"
+
to add a new package.https://github.com/kukushi/SideMenu.git
into the search field.import SideMenu
to import SideMenu
.SideMenu
in storyboard:SideMenuController
and Module to SideMenuSwift
.SideMenuController
to each of them.SideMenu.Menu
, Class to SideMenuSegue
and Module to SideMenuSwift
.SideMenu.Content
, Class to SideMenuSegue
and Module to SideMenuSwift
.SideMenuController
‘s Attribute inspector.SideMenu
programmatically:swift
import UIKit
import SideMenuSwift
// If you are using Carthage, uses `import SideMenu`
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@objc func applicationDidFinishLaunching(_ application: UIApplication) {
let contentViewController = ...
let menuViewController = ...
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = SideMenuController(contentViewController: contentViewController,
menuViewController: menuViewController)
window?.makeKeyAndVisible()
return true
}
}
Use the sideMenuController
method which provided in UIViewController
‘s extension to get the parent SideMenuController
:
viewController.sideMenuController?.revealMenu()
All the preferences of SideMenu can be found in SideMenuController.preferences
. It’s recommend to check out the Example
to see how those options will take effect.
SideMenuController.preferences.basic.menuWidth = 240
SideMenuController.preferences.basic.statusBarBehavior = .hideOnMenu
SideMenuController.preferences.basic.position = .below
SideMenuController.preferences.basic.direction = .left
SideMenuController.preferences.basic.enablePanGesture = true
SideMenuController.preferences.basic.supportedOrientations = .portrait
SideMenuController.preferences.basic.shouldRespectLanguageDirection = true
// See a lot more options on `Preferences.swift`.
One of the coolest features of SideMenu
is caching.
// Cache the view controllers somewhere in your code
sideMenuController?.cache(viewController: secondViewController, with: "second")
sideMenuController?.cache(viewController: thirdViewController, with: "third")
// Switch to it when needed
sideMenuController?.setContentViewController(with: "second")
What about the content view controller initialized from the Storyboard? We can use the preferences to apply a default key for it!
SideMenuController.preferences.basic.defaultCacheKey = "default"
What if we can’t want to load all the content view controllers so early? We can use lazy caching:
sideMenuController?.cache(viewControllerGenerator: { self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") }, with: "second")
sideMenuController?.cache(viewControllerGenerator: { self.storyboard?.instantiateViewController(withIdentifier: "ThirdViewController") }, with: "third")
SideMenu is available under the MIT license. See the LICENSE file for more info.