Dropdown with custom view swift || dropdown option with customcell in swift

 Solution:

{

    let dropDown = DropDown()

    var control:UIView! = btn.plainView

    var items:[String] = []

    for value in values {

        let name = value["name"]

        items.append("\(name)")

    }

    dropDown.anchorView = sender != nil ? sender : control // UIView or UIBarButtonItem

    dropDown.selectionBackgroundColor = .gray

    dropDown.direction = .any

    dropDown.dataSource = items

    dropDown.cellHeight = 60

    dropDown.separatorColor = .gray

    dropDown.cellNib = UINib(nibName"Cell"bundlenil)

    dropDown.customCellConfiguration = { [viewControl] (index: Index, item: String, cell: DropDownCell) -> Void in

       guard let cell = cell asCell else { return }

        

        cell.optionLabel.text = item


       // Setup your custom UI components

    }


   

    dropDown.selectionAction = { [unowned viewControl] (index: Int, item: Stringin

             // Setup your after selection code here 

    

    }

    dropDown.show()


}


The above are the code for showing dropdown with custom cell

Below code is that for the cell configuration







The above is the cell and the cell connection configurations.You must have to create a label with optionLabel and connect but its not for your cell code.If you are derived the cell from drodown as like below then it will works good

import UIKit

import DropDown


class CellDropDownCell {

    @IBOutlet weak var nameBtnUIButton!

    

    override func awakeFromNib() {

        super.awakeFromNib()


        // Initialization code

    }


    override func setSelected(_ selected: BoolanimatedBool) {

        super.setSelected(selected, animated: animated)


        // Configure the view for the selected state

    }

}


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