Giter Club home page Giter Club logo

joncontextmenu's Introduction

JonContextMenu

CocoaPods Compatible License

A beautiful and minimalist arc menu like the Pinterest one, written in Swift. Allows you to add up to 8 items and customize it to the way you like!

Gif

How to use

// First import the library to your class file.
import JonContextMenu

// Create an array of type "JonItem" for the items you desire to show.
// "JonItem" constructor takes an id to identify the object, a String to be the title of the item and 
// an UIImage to be the icon of the item.
let items = [JonItem(id: 1, title: "Google"   , icon: UIImage(named:"google")),
             JonItem(id: 2, title: "Twitter"  , icon: UIImage(named:"twitter")),
             JonItem(id: 3, title: "Facebook" , icon: UIImage(named:"facebook")),
             JonItem(id: 4, title: "Instagram", icon: UIImage(named:"instagram"))]

The JonItem contructor has also a fourth optional parameter called "data". You can use it to add some object that you would like to have access later when selecting this item

JonItem(id: 1, title: "Google", icon: UIImage(named:"google", data: <<SOMEOBJECT>>)
// Then, create an instance of JonContextMenu setting your array to it.
let contextMenu = JonContextMenu().setItems(options).build()

// Finally, add the "contextMenu" to the view you wish.
<<YOURVIEW>>.addGestureRecognizer(contextMenu)

To show the menu, just long press the view you set the JonContextMenu.

Delegates

If you want to be notified when some interaction happens on the context menu, JonContextMenu has with 5 functions that you can implemement:

// Implement the JonContextMenuDelegate to your ViewController 
class ViewController:JonContextMenuDelegate{

    func menuOpened(){
      // Called when the JonContextMenu opens
    }
    func menuClosed(){
      // Called when the JonContextMenu closes
    }
    func menuItemWasSelected(item:JonItem){
      // Called when the user selects one of the items
    }
    func menuItemWasActivated(item:JonItem){
      // Called when the user interacts with one of the items
    }
    func menuItemWasDeactivated(item:JonItem){
      // Called when the user stops interacting with one of the items
    }
}

// Then, when creating an instance of JonContextMenu, set the delegate.
let contextMenu = JonContextMenu()
                  .setItems(options)
                  .setDelegate(self)
                  .build()

Custom Configuration

The default visual configuration for JonContextMenu will probably be enough for you, but if you wish to make a few custom modification, the library has some functions that allow you to personalize it as you wish.

JonContextMenu()

// The number of items to be displayed, it can be up to 8 items.
.setItems(options)

// The delegate to notify when an item is selected.
.setDelegate(self)

// The background colour of the view. The default colour is white and the default alpha is 0.9
.setBackgroundColorTo(.white, withAlpha: 0.5)

// The idle colour of the items(when there is no interaction). The default colour is white
.setItemsDefaultColorTo(.black)

// The idle colour of the items' icon(when there is no interaction).  There is no deafault colour. 
// If you don't set it, the icon will have no tint colour and will display the original image's colour
.setIconsDefaultColorTo(.white)

// The active colour of the items(when there is interaction). The default colour is darkRed
.setItemsActiveColorTo(.white)

// The active colour of the items' icon(when there is interaction). There is no deafault colour. 
// If you don't set it, the icon will have no tint colour and will display the original image's colour
.setIconsActiveColorTo(.black)

// The colour of the title of the items. The default colour is darkGray
.setItemsTitleColorTo(.black)

// The size of the title of the items. The default size is 72
.setItemsTitleSizeTo(50)

// The colour of touch point circle. The default colour is darkGray
.setTouchPointColorTo(.black)

Installation

CocoaPods

To integrate JonContextMenu to your project using CocoaPods, specify it in your Podfile:

target '<Your Target Name>' do
    pod 'JonContextMenu', :git => 'https://github.com/jonSurrey/JonContextMenu.git', :branch => 'master'
end

Then, run the following command:

$ pod install

Manual installation

First download the "JonContextMenu" folder. Then, in Xcode, right-click on the root of your project node in the project navigator. Click "Add Files" to “YOURPROJECTNAME”. In the file chooser, navigate to where "JonContextMenu" folder is and select JonContextMenu.xcodeproj. Click "Add" to add JonContextMenu.xcodeproj as a sub-project.

Select the top level of your project node to open the project editor. Click the YOUR_PROJECT_NAME target, and then go to the General tab.

Scroll down to the Embedded Binaries section. Drag JonContextMenu.framework from the Products folder of JonContextMenu.xcodeproj onto this section.

Clean and rebuild your project, and you should be good to go!

Collaboration

This is a simple libray that I created to help myself in my own work since I didnt find any other that would do what I wanted. I know that there is still here a lot of space for improvements and adding new features, so please, any ideas or issues, feel free to collaborate!

Author

Jonathan Martins, [email protected]

License

JonContextMenu is available under the MIT license. See the LICENSE file for more info.

joncontextmenu's People

Contributors

jonathanjussi avatar jonsurrey avatar oggerschummer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

joncontextmenu's Issues

Not working fine on iPad

Hi,
on the iPad the overlay is always based on the window bounds.
This may be OK for iPhone, but here it doesn´t look well.
Besides this the texts for the items are shown on the left border of the window.
Having the menu on the right (e.g. put it on an UImage View) this does not work well.
Regards
Oggerschummer

Can not cast to collectionView

Hello,
I have a collectionview and I want to get the cell that is selected by longPress context menu.
For this I'm trying to send collectionViewCell as data in ContextMenuitem but it's not working.
I've even tried to send IndexPath as data and still not working.
Any solution for that?

No check for protocol methods implemented in delegate

The code does not check if the linked delegate actually implemented a method before calling it.
This should be done as e.g. the menuOpened method my not be of interest.
Most of the time only menuItemWasSelected will be needed.

Without the checks the code crashes.

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.