con

ContextMenuSwift

A better version of iOS 13 Context Menu

Showing:

Popularity

Downloads/wk

0

GitHub Stars

72

Maintenance

Last Commit

6mos ago

Contributors

2

Package

Dependencies

0

License

Apache License, Version 2.0

Categories

Readme

ContextMenuSwift

Linkedin: umerjabbar Twitter: @Umer_Jabbar License Xcode 10.0+ iOS 10.0+ Swift 4.0+ Cocoapods

Installation 📱

Just add ContextMenuSwift to your Podfile and pod install. Done!

pod 'ContextMenuSwift'

Usage ✨

Example 1

Show the menu of string values on your view

CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)

Example 2

Update menu items async

CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
    CM.items = ["Item 1"]
    CM.updateView(animated: true)
}

Example 3

Update targeted view async

CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
    CM.changeViewTargeted(newView: YourView)
    CM.updateView(animated: true)
}

Example 4

Show menu with icons

let share = ContextMenuItemWithImage(title: "Share", image: #imageLiteral(resourceName: "icons8-upload"))
let edit = "Edit"
let delete = ContextMenuItemWithImage(title: "Delete", image: #imageLiteral(resourceName: "icons8-trash"))
CM.items = [share, edit, delete]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)

Delegate

You can check events by implement ContextMenuDelegate

extension ViewController : ContextMenuDelegate {
    
    func contextMenu(_ contextMenu: ContextMenu, targetedView: UIView, didSelect item: ContextMenuItem, forRowAt index: Int) -> Bool {
        print(item.title)
        return true //should dismiss on tap
    }
    
    func contextMenuDidAppear(_ contextMenu: ContextMenu) {
        print("contextMenuDidAppear")
    }
    
    func contextMenuDidDisappear(_ contextMenu: ContextMenu) {
        print("contextMenuDidDisappear")
    }
 
}

Requirements

  • Xcode 9+
  • Swift 4.0
  • iOS 10+

License

This project is under MIT license. For more information, see LICENSE file.

Credits

ContextMenuSwift was developed while trying to implement iOS 13 context menu with a tap gesture.

It will be updated when necessary and fixes will be done as soon as discovered to keep it up to date.

You can find me on Twitter @Umer_Jabbar and Linkedin umerjabbar.

Enjoy! 🤓

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial