PopMenu
PopMenu is designed as a quick popup action menu, much like an action sheet in iOS. If you want an action sheet that looks great, you're in the right place!
PopMenu has the abilities of:
-
Automatically position menu on screen if you specify the source view, like a popup. (edge detection)
-
Full customization (icons, fonts, colors, background, styles, corners, height, status bar... you name it).
-
Pan gesture control. (like 3D touch shortcuts on apps in home screen)
-
Haptics enabled for selection or pan gesture.
? Demo / Example
Download or fork the repo and open the given Example
Xcode project to try it out yourself!
What's a better way to know what PopMenu
offers than some screenshots? Here's some to show you what you can do with PopMenu
:
⚙️ Installation
For CocoaPods
Install PopMenu using CocoaPods, add it to your Podfile:
‼️
PopMenu
was actually taken so let's call itNewPopMenu
'cause why not?
For Carthage
Install PopMenu using Carthage, add it to your Cartfile:
⚠️ Requirements
- Xcode 8.0 +
- iOS 9.0 +
- Swift 4.0 +
??? How to Use
Integrating PopMenu is extremely easy with a familiar workflow like presenting UIAlertController
with UIAlertAction
Import Library
Basic Usage
There are 2 ways to present the menu in your view controller:
-
Use the default manager
-
Use the
PopMenuViewController
class directly
You can, however, choose either way to have the same result, whichever works best for you.
Which Should I Use?
-
Use the default manager if you want quick setup and present menu seamlessly.
-
Use the
PopMenuViewController
class directly if you want to have more control.
If you don't want to scroll, click the link to jump forward:
Basic Usage - Using Controller
Basic Usage - Using Manager
The quickest way would be to use PopMenuManager
's default singleton with no additional setup required:
Add actions if you're using the manager:
Or if you prefer the good ol' way similar to presenting a UIAlertController
with UIAlertAction
, you can add each action like that:
That's how you set the actions for the menu.
Now all you have to do is to simply call present()
on the manager, either pass the view controller in the on
argument or PopMenuManager will automatically fetch the current top view controller to present the menu on top:
Both should work just fine, but still, using manager.present(on: ...)
manually would be a safer way to go for presenting.
Basic Usage - Using Controller
If you are using PopMenuManager
to handle PopMenu, you can skip this section.
Manually initialize the controller:
Add actions inside the initializer:
Finally, to present the menu all you have to do is call present
method in your ViewController like a normal view controller:
Source View
By default, PopMenu
will present in the center of your screen. If you want it to display on the relative position of a view that the user tapped, you can pass the source view in like this:
Selection Callback
In order to know which action button is tapped, there are two ways of doing that:
- Action Handler
- Delegate
Action Handler
Simply pass the handler when instanstiating the action:
Delegate Method
You'll need to comform to PopMenuViewControllerDelegate
protocol and then implement the method popMenuDidSelectItem(at index: Int)
in your view controller:
Dismissal Callback
If you'd want more control to do additional steps when the menu is dismssed, you can do it like this:
Configurations
By default, PopMenu has pan gesture enabled, you can toggle it here:
By default, PopMenu has haptics enabled, you can toggle it here:
That's basically it! Congrats!
If you're a customization lover like me, then read along:
?? Customization
Before moving on, customization should be applied before presenting the menu, and assume that you already have a:
variable of PopMenuManager.default
called -> manager
.
----- or -----
variable of PopMenuViewController
called -> menu
.
Action Dismissal // Default: true
If you don't want the menu to auto-dismiss once a selection has been performed, you can change the property:
Background styles // Default: .dimmed(color: .black, opacity: 0.4)
There are mainly 3 types of background styles:
- Blurred (dark, light & extra Light)
- Dimmed (color & opacity)
- None
Simply set the popMenuBackgroundStyle
on the appearance property using .
notation:
Action Color // Default: white
To bulk set action colors is simple and straightforward:
To set each action with different color, you'll have to specify in the color
parameter initializer of action PopMenuDefaultAction
:
Background Color(s) // Default: flat black gradient
There are 2 types of background colors:
- Solid fill (one color)
- Gradient fill (two colors)
To set the background color(s) of the menu:
Action Font // Default: .systemFont(ofSize: 16, weight: .semiBold)
To set the font of all actions:
Corner Radius // Default: 24
To set corner radius of the menu container:
Action Height // Default: 50
To set height of each action:
Action Item Separator // Default: none
To set the action item separator:
Status Bar Style // Default: automatic detection based on background color
If you don't want PopMenu
to use automatic detection to set status bar style, you can override it:
More customization coming, stay tuned...