Multiline cells: Is that still impossible?
EmmaVvv opened this issue · comments
I'm not able to configure DropDown to show multiline cells if the content is too long. Any suggestions? Is that still impossible with this pod ?
By the way, this isn't working
` dropDown.customCellConfiguration = { (index: Int, item: String, cell: DropDownCell) -> Void in
cell.optionLabel.textAlignment = .center
cell.optionLabel.numberOfLines = 0
cell.optionLabel.lineBreakMode = .byWordWrapping
}`
You can check out a concrete example in the Demo inside this project (go to ViewController.swift, line 125).
For this you have to:
Create a DropDownCell subclass (e.g. MyCell.swift)
class MyCell: DropDownCell {
@IBOutlet weak var logoImageView: UIImageView!
}
Create your custom xib (e.g. MyCell.xib) and design your cell view in it
Link the cell in your xib to your custom class
At least have a label in your xib to link to the optionLabel IBOutlet in code (optionLabel is a property of DropDownCell)
Then, you simply need to do this:
let dropDown = DropDown()
// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem
// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]
/*** IMPORTANT PART FOR CUSTOM CELLS ***/
dropDown.cellNib = UINib(nibName: "MyCell", bundle: nil)
dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
guard let cell = cell as? MyCell else { return }
// Setup your custom UI components
cell.logoImageView.image = UIImage(named: "logo_(index)")
}
/*** END - IMPORTANT PART FOR CUSTOM CELLS ***/
And you're good to go! 🙆
For a complete example, don't hesitate to check the demo app and code.