Giter Club home page Giter Club logo

popmenu-1's Introduction

⚙️ Installation

For CocoaPods

Install PopMenu using CocoaPods, add it to your Podfile:

PopMenu was actually taken so let's call it NewPopMenu 'cause why not?

pod 'NewPopMenu'

For Carthage

Install PopMenu using Carthage, add it to your Cartfile:

github "CaliCastle/PopMenu"

⚠️ 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 (NewPopMenu)

import NewPopMenu

Basic Usage

There are 2 ways to present the menu in your view controller:

  1. Use the default manager

  2. 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 Manager

Basic Usage - Using Controller


Basic Usage - Using Manager

The quickest way would be to use PopMenuManager's default singleton with no additional setup required:

let manager = PopMenuManager.default

Add actions if you're using the manager:

manager.actions = [
    PopMenuDefaultAction(title: "Action Title 1", image: UIImage(named: "icon"),
    PopMenuDefaultAction(title: "Action Title 2", image: UIImage(named: "icon")
]

Or if you prefer the good ol' way to present a UIAlertController with actionSheet type, you can add each action like this:

let action1 = PopMenuDefaultAction(title: "Action Title 1", image: UIImage(named: "icon")
let action2 = PopMenuDefaultAction(title: "Action Title 2", image: UIImage(named: "icon")

manager.addAction(action1)
manager.addAction(action2)

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:

// Show menu without specifying which controller
manager.present()

// Or you can specify the controller to present on
manager.present(on: self)

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

Manually initialize the controller:

let menuViewController = PopMenuViewController()

Action Callback

In order to know which action button is tapped, you'll need to comform to PopMenuViewControllerDelegate protocol and then implement the method popMenuDidSelectItem(at index: Int) in your view controller:

class ViewController: UIViewController {
    
    func presentMenu() {
        let manager = PopMenuManager.default
        
        manager.popMenuDelegate = self
        
        manager.present(on: self)
    }

}

extension ViewController: PopMenuViewControllerDelegate {

    func popMenuDidSelectItem(at index: Int) {
        // Do stuff here...
    }
    
}

📗 Check Documentation

Documentation is available at https://calicastle.github.io/PopMenu/

popmenu-1's People

Contributors

calicastle avatar

Watchers

Carabineiro 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.