Create a dropDown Menu with array of values iOS swift

Solution:

It was easy to show a dropdown menu when click on one button.

Goto podfile and add the below code in that


    pod 'DropDown'


Update the pod in command line.It will install the dropdown in your app

Then goto your required Viewcontroller and import dropdown like below.



import DropDown



In you button action add the below code


    func didTapOnBtn(_ sender: AnyObject){


        let btn = sender as! UIButton

        let dropDown = DropDown()
        dropDown.anchorView = sender as? AnchorView
        dropDown.direction = .any
        dropDown.dataSource = ["list1","list2","list3"]
        dropDown.cellNib = UINib(nibName: "Cell", bundle: nil)
        dropDown.width = 150
        dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
            guard let cell = cell as? Cell else { return }
            cell.Label.text = item
        }
        
        dropDown.selectionAction = { [unowned self] (index: Int, item: String) in

}

        dropDown.show()

}


You can create a cell in XIB and assign that as DropDownCell in your class like below


import UIKit
import DropDown

class Cell: DropDownCell {

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift