Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umerjabbar/ContextMenuSwift
A better version of iOS 13 Context Menu
https://github.com/umerjabbar/ContextMenuSwift
context-menu contextmenu dropdown dropdown-menus dropdownlist dropdownmenu framework ios menu menubar menus pod swift
Last synced: 3 months ago
JSON representation
A better version of iOS 13 Context Menu
- Host: GitHub
- URL: https://github.com/umerjabbar/ContextMenuSwift
- Owner: umerjabbar
- Created: 2020-04-30T21:55:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T09:22:48.000Z (10 months ago)
- Last Synced: 2024-07-04T10:15:18.518Z (7 months ago)
- Topics: context-menu, contextmenu, dropdown, dropdown-menus, dropdownlist, dropdownmenu, framework, ios, menu, menubar, menus, pod, swift
- Language: Swift
- Homepage:
- Size: 8.12 MB
- Stars: 298
- Watchers: 7
- Forks: 28
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ios - ContextMenuSwift
- awesome - ContextMenuSwift - A better version of iOS 13 Context Menu (swift)
- awesome - ContextMenuSwift - A better version of iOS 13 Context Menu (swift)
README
# ContextMenuSwift
[![Linkedin: umerjabbar](http://img.shields.io/badge/linkedin-umerjabbar-70a1fb.svg?style=flat)](https://www.linkedin.com/in/umerjabbar)
[![Twitter: @Umer_Jabbar](http://img.shields.io/badge/twitter-%40Umer_Jabbar-70a1fb.svg?style=flat)](https://twitter.com/Umer_Jabbar)
![License](https://img.shields.io/cocoapods/l/Hero.svg?style=flat)
![Xcode 10.0+](https://img.shields.io/badge/Xcode-9.0%2B-blue.svg)
![iOS 10.0+](https://img.shields.io/badge/iOS-10.0%2B-blue.svg)
![Swift 4.0+](https://img.shields.io/badge/Swift-4.0%2B-orange.svg)
[![Cocoapods](http://img.shields.io/badge/Cocoapods-available-green.svg?style=flat)](https://cocoapods.org/pods/ContextMenuSwift)## Installation 📱
Just add `ContextMenuSwift` to your Podfile and `pod install`. Done!
```ruby
pod 'ContextMenuSwift'
```## Usage ✨
### Example 1
Show the menu of string values on your view
```swift
CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)
```### Example 2
Update menu items async
```swift
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
```swift
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
Change the horizontal direction of menu
```swift
CM.MenuConstants.horizontalDirection = .right
CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)
```### Example 5
Show menu with icons
```swift
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
```swift
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](https://twitter.com/Umer_Jabbar) and Linkedin [umerjabbar](https://www.linkedin.com/in/umerjabbar/).
Enjoy! 🤓