Giter Club home page Giter Club logo

contextmenuswift's Introduction

ContextMenuSwift

Linkedin: umerjabbar Twitter: @Umer_Jabbar License Xcode 10.0+ iOS 10.0+ Swift 4.0+ Cocoapods

Installation ๐Ÿ“ฑ

Just add ContextMenuSwift to your Podfile and pod install. Done!

pod 'ContextMenuSwift'

Usage โœจ

Example 1

Show the menu of string values on your view

CM.items = ["Item 1", "Item 2", "Item 3"]
CM.showMenu(viewTargeted: YourView, delegate: self, animated: true)

Example 2

Update menu items async

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

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

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

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

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 and Linkedin umerjabbar.

Enjoy! ๐Ÿค“

contextmenuswift's People

Contributors

kveldkamp avatar sitatec avatar umerjabbar 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  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  avatar  avatar

contextmenuswift's Issues

Movement of targetedView is going beyond safe area in iOS 17.0

The movement of the targetedView goes beyond the safe area (goes behind dynamic island) in case of long list of options. Although i would like to know if it is possible to restrict the movement of targetedView and just show the dropdown menus only. (I know a better option is to implement a tableview but this lib goes well with implementation throughout the project)

iOS 17.0
Device : Simulator iPhone 15 pro

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-04-03.at.08.56.30.mp4

Thankyou

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.