diff --git a/Demo/ViewController.swift b/Demo/ViewController.swift index f9ec1e6..f22fd98 100644 --- a/Demo/ViewController.swift +++ b/Demo/ViewController.swift @@ -237,7 +237,8 @@ class ViewController: UIViewController { // You can also use localizationKeysDataSource instead. Check the docs. chooseDropDown.dataSource = [ "Lorem ipsum dolor", - "sit amet consectetur", + "sit amet consectetur sit amet consectetur sit amet consectetur sit amet consectetur sit amet consectetur", + // long string for testing multi-line support in tableview cell. "cadipisci en..." ] diff --git a/DropDown/resources/DropDownCell.xib b/DropDown/resources/DropDownCell.xib index ebfed0b..2abb023 100644 --- a/DropDown/resources/DropDownCell.xib +++ b/DropDown/resources/DropDownCell.xib @@ -1,35 +1,43 @@ - - + + + + + - + + - + - + - - + + + diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index 6f92889..a1250e6 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -1018,6 +1018,8 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { cell.optionLabel.textColor = textColor cell.optionLabel.font = textFont + cell.optionLabel.numberOfLines = 0 + cell.optionLabel.lineBreakMode = .byWordWrapping cell.selectedBackgroundColor = selectionBackgroundColor if let cellConfiguration = cellConfiguration { @@ -1029,6 +1031,14 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { customCellConfiguration?(index, dataSource[index], cell) } + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return UITableViewAutomaticDimension + } + + public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { + return cellHeight + } + public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { cell.isSelected = selectedRowIndices.first{ $0 == (indexPath as NSIndexPath).row } != nil }