DropDown for iOS
Posted By : Aditya Kumar Sharma | 28-Jun-2017
In this blog we are going to use material design Drop down for iOS.
So intially we have to install Cocoapods of DropDown for that follow these steps:
- Add
pod 'DropDown'
to our project Podfile. - Then installing the pod by running
pod install
.
Now we will be seeing usage of this DropDown. How to show list on Button click. How to customize it and other things.
- So go to Storyboard > ViewController where you have to show dropDown.
- Add Button to View and make an outlet and Action of the button (Dropdown can be shown on View or Barbutton also).
@IBOutlet weak var tradeButton: UIButton!
@IBAction func chooseTradeButton(_ sender: Any) {
}
- ?Now open the ViewController and add import DropDown to the .swift file.
- Create an object of DropDown.
var tradeDropDown = DropDown()
- Will create a func to intialise dropdown func initialiseTradeDropDown() and write these in this func.
// The view to which the drop down will appear on
tradeDropDown.anchorView = tradeButton // UIView or UIBarButtonItem
// The list of items to display. Can be changed dynamically
tradeDropDown.dataSource = ["CarBrake", "BrakeSole", "Car gear", "Wheels", "Head Lights"]
- Now we will be changing the title of Button as the items are selected from the list. So add following in initialiseDropDown().
// Action triggered on selection
tradeDropDown.selectionAction = { [unowned self] (index, item) in
self.tradeButton.setTitle(item, for: .normal)
}
- Last thing we are left out is to show list when we click button. So add following in the button action we have made.
tradeDropDown.show()
- Run the project and we click on the button
on selection
Reference : https://github.com/AssistoLab/DropDown
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Aditya Kumar Sharma
Aditya is a bright iOS developer, have knowledge of objective C, swift, swift 3, JSON, Core data and iPhone development. Apart from that he loves to travel and explore new things.