igongora / UIDropDown

An elegant dropdown for iOS written in Swift.
MIT License
87 stars 17 forks source link

UIDropDown

An elegant dropdown for iOS written in Swift.

Overview

UIDropDown allows you to pick an option in a table just like dropdowns in web. It contains 3 differents animations to present the options table and can be modified in many ways.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate UIDropDown into your Xcode project using CocoaPods, specify it in your Podfile:

target '<Your Target Name>' do
    pod 'UIDropDown'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate UIDropDown into your Xcode project using Carthage, specify it in your Cartfile:

github "igongora/UIDropDown"

Run carthage update to build the framework and drag the built DropDown.framework into "Embedded binaries".

Usage

Use UIDropDown it's as easy as set the array of strings you want to show and a placeholder

drop = UIDropDown(frame: CGRect(x: 0, y: 0, width: 200, height: 30))
drop.center = CGPoint(x: self.view.frame.midX, y: self.view.frame.midY)
drop.placeholder = "Select your country..."
drop.options = ["Mexico", "USA", "England", "France", "Germany", "Spain", "Italy", "Canada"]
drop.didSelect { (option, index) in
                     self.label.text = "You just select \(option) at index: \(index)"
                     print("You just select: \(option) at index: \(index)")
               }
self.view.addSubview(drop) 

The "didSelect" method will return the string and index selected

drop.didSelect { (option, index) in
                     self.label.text = "You just select \(option) at index: \(index)"
                     print("You just select: \(option) at index: \(index)")
               }

Requirements

Author

Isaac Gongora, igongoracastano@gmail.com

License

UIDropDown is available under the MIT license