Code Monkey home page Code Monkey logo

swiftymenu's Introduction

SwiftyMenu

Cocoapod Version MIT License
Facebook: @KarimEbrahemAbdelaziz Twitter: @k_ebrahem_

SwiftyMenu is simple yet powerfull drop down menu component for iOS. It allow you to have drop down menu that doesn't appear over your views, which give you awesome user experience.

Screenshots

Requirements

  • Xcode 10.2+
  • Swift 5+
  • iOS 10+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SwiftyMenu into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftyMenu', '~> 0.6.4'

Usage

Storyboard

We are supporting Generic Data Source, all you have to do is conforming to our Generic Protocol on which type you want to add to the menu:

// Example on String. You can change it to what ever type you want ;)
// String extension to conform SwiftyMenuDisplayable Protocl
extension String: SwiftyMenuDisplayable {
    public var displayableValue: String {
        return self
    }
    
    public var retrivableValue: Any {
        return self
    }
}

Then setup your view controller:

// Connect view in storyboard with you outlet
@IBOutlet private weak var dropDownMenu: SwiftyMenu!

// Define your Generic items array)
private let items: [SwiftyMenuDisplayable] = ["Option 1", "Option 2", "Option 3", "Option 4"]

// Assign the component that implement SwiftyMenuDelegate to SwiftyMenu component
dropDownMenu.delegate = self

// Give array of items to SwiftyMenu
dropDownMenu.items = items

Then implement SwiftyMenuDelegate:

extension ViewController: SwiftyMenuDelegate {
    // Get selected option from SwiftyMenu
    func swiftyMenu(_ swiftyMenu: SwiftyMenu, didSelectItem item: SwiftyMenuDisplayable, atIndex index: Int) {
        print("Selected item: \(item), at index: \(index)")
    }
    
    // SwiftyMenu drop down menu will expand
    func swiftyMenu(willExpand swiftyMenu: SwiftyMenu) {
        print("SwiftyMenu willExpand.")
    }

    // SwiftyMenu drop down menu did expand
    func swiftyMenu(didExpand swiftyMenu: SwiftyMenu) {
        print("SwiftyMenu didExpand.")
    }

    // SwiftyMenu drop down menu will collapse
    func swiftyMenu(willCollapse swiftyMenu: SwiftyMenu) {
        print("SwiftyMenu willCollapse.")
    }

    // SwiftyMenu drop down menu did collapse
    func swiftyMenu(didCollapse swiftyMenu: SwiftyMenu) {
        print("SwiftyMenu didCollapse.")
    }
}

Also you can use callbacks to know what happen:

// Support different callbacks for different events
dropDownMenu.didExpand = {
    print("SwiftyMenu Expanded!")
}

dropDownMenu.didCollapse = {
    print("SwiftyMeny Collapsed")
}

dropDown.didSelectItem = { menu, item, index in
    print("\(item) at index: \(index)")
}

CustomizeUI

You can configure SwiftyMenu from Storyboard or Code as following:

// Change option's row height (default 35)
dropDownMenu.rowHeight = 35

// Change option's drop down menu height 
// default is 0, which make drop down height = number of options * rowHeight
dropDownMenu.listHeight = 150

// Change drop down menu border width
dropDownMenu.borderWidth = 1.0

// Change drop down menu scroll behavior 
dropDownMenu.scrollingEnabled = false

// Change drop down menu default colors
dropDownMenu.borderColor = .black
dropDownMenu.itemTextColor = .red
dropDownMenu.placeHolderColor = .blue
dropDownMenu.menuHeaderBackgroundColor = .lightGray
dropDownMenu.rowBackgroundColor = .orange
dropDown.separatorColor = .white

// Change drop down menu default expand and collapse animation
dropDownMenu.expandingAnimationStyle = .spring(level: .low)
dropDownMenu.expandingDuration = 0.5
dropDownMenu.collapsingAnimationStyle = .linear
dropDownMenu.collapsingDuration = 0.5

TODO

  • Automate release new version to Cocoapods from Github Actions.
  • Add CHANGELOG file for the project.
  • Allow custom header and options cells.
  • Allow different interactions to dismiss SwiftyMenu.
  • Allow to customize the default seperator.
  • Support Generic DataSource.
  • Support multi selection in SwiftMenu ๐Ÿ”ฅ.
  • Support multi SwiftyMenu in one screen.
  • Support stack view and add example.
  • Support call backs and delegation.
  • Support different types of Animations.
  • Add different customization to colors for default cells.

And much more ideas to make it solid drop down menu for iOS projects ๐Ÿ˜Ž๐Ÿ’ช๐Ÿป

Android

Author

Karim Ebrahem, [email protected]

License

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

Credits

You can find me on Twitter @k_ebrahem_.

It will be updated when necessary and fixes will be done as soon as discovered to keep it up to date.

Enjoy!

swiftymenu's People

Contributors

amrangry avatar aramy23 avatar jasminpsimform avatar karimebrahemabdelaziz avatar mostafanafie avatar zyadgalal 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.