Giter Site home page Giter Site logo

menuitemkit's Introduction

MenuItemKit

MenuItemKit provides image and block(closure) support for UIMenuItem.

MenuItemKit is a Swift project but Objective-C is supported without any doubt.

Screenshot

Install

Swift Package

Add this repo URL to your Swift package dependencies.

CocoaPods

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:

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:

@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 UIMenuItems 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.

About Me

  • Twitter: @_cxa
  • Apps available in App Store: http://lazyapps.com
  • 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.

menuitemkit's People

Contributors

alexpopov avatar coeur avatar cxa avatar jabernethy avatar stephanheilner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.