Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cxa/MenuItemKit
UIMenuItem with image and closure(block) action
https://github.com/cxa/MenuItemKit
Last synced: about 1 month ago
JSON representation
UIMenuItem with image and closure(block) action
- Host: GitHub
- URL: https://github.com/cxa/MenuItemKit
- Owner: cxa
- License: mit
- Created: 2016-01-17T05:17:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-07T15:21:09.000Z (over 1 year ago)
- Last Synced: 2024-11-25T05:32:58.815Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 690 KB
- Stars: 850
- Watchers: 16
- Forks: 67
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - MenuItemKit - UIMenuItem with image and block(closure) (UI / Menu)
- awesome-swift - MenuItemKit - `UIMenuItem` with image and block (closure) support. (Libs / UI)
- awesome-swift - MenuItemKit - `UIMenuItem` with image and block (closure) support. (Libs / UI)
- awesome-ios-star - MenuItemKit - UIMenuItem with image and block(closure) (UI / Menu)
- fucking-awesome-swift - MenuItemKit - `UIMenuItem` with image and block (closure) support. (Libs / UI)
- awesome-swift-cn - MenuItemKit - `UIMenuItem` with image and block (closure) support. (Libs / UI)
- awesome-swift - MenuItemKit - UIMenuItem with image and closure(block) action ` 📝 9 months ago` (UI [🔝](#readme))
- awesome - MenuItemKit - UIMenuItem with image and closure(block) action. (OOM-Leaks-Crash / Menu-PopupView)
README
> **Warning**
> `UIMenuController` is deprecated from iOS 16. Use `UIEditMenuInteraction` instead.# MenuItemKit
`MenuItemKit` provides image and block(closure) support for `UIMenuItem`.
`MenuItemKit` is a Swift project but Objective-C is supported without any doubt.
![Screenshot](Screenshot.png)
## Install
### Swift Package
Add this repo URL to your Swift package dependencies.
### CocoaPods
```ruby
pod 'MenuItemKit', '~> 4.0.0'
```### Xcode subproject
1. Add the `MenuItemKit` repository as a submodule of your application’s repository.
2. Drag and drop `MenuItemKit.xcodeproj` into your application’s Xcode project or workspace.
3. On the “General” tab of your application target’s settings, add `MenuItemKit.framework` to the “Embedded Binaries” section.If you would prefer to use Carthage, please pull request.
## How to use
`MenuItemKit` is very easy to adopt, it provides only 2 APIs:
``` swift
typealias MenuItemAction = (UIMenuItem) -> ()extension UIMenuItem {
convenience init(title: String, image: UIImage?, action: MenuItemAction)
convenience init(title: String, action: MenuItemAction)
}
```For Objective-C, `MenuItemKit` provides prefixed API names for safe reasons:
```objc
@interface UIMenuItem (SWIFT_EXTENSION(MenuItemKit))
- (nonnull instancetype)mik_initWithTitle:(NSString * _Nonnull)title image:(UIImage * _Nullable)image action:(MenuItemAction _Nonnull)action;
- (nonnull instancetype)mik_initWithTitle:(NSString * _Nonnull)title action:(MenuItemAction _Nonnull)action;
@end
```Just init `UIMenuItem`s with above APIs, and set them to `menuItems` of `UIMenuItemController`. `MenuItemKit` will take care of the rest parts, you don't need to add any code related to responder chain in your view or view controller.
Check dome projects (both Swift and Objective-C are provided) for more details.
## Advance Usage
For menu items out of your control, you can use `static func installTo(responder: UIResponder, shouldShowForAction: @escaping (Selector, Bool) -> Bool = default)` to configure items visibility. Check [AutoPopupMenuControllerDemo](AutoPopupMenuControllerDemo).
## About Me
* Twitter: [@_realazy](https://twitter.com/_realazy)
* Apps available in App Store:
* PayPal: xianan.chen+paypal 📧 gmail.com, buy me a cup of coffee if you find it's useful for you, thanks.## License
`MenuItemKit` is released under the MIT license. In short, it's royalty-free but you must keep the copyright notice in your code or software distribution.