diff --git a/DropDown/helpers/DPDConstants.swift b/DropDown/helpers/DPDConstants.swift index 52047be..5a71759 100644 --- a/DropDown/helpers/DPDConstants.swift +++ b/DropDown/helpers/DPDConstants.swift @@ -35,6 +35,7 @@ internal struct DPDConstant { static let CornerRadius: CGFloat = 2 static let RowHeight: CGFloat = 44 static let HeightPadding: CGFloat = 20 + static let NumblerOfLines: Int = 1 struct Shadow { diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index f41e8dd..dac9a28 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -352,6 +352,15 @@ public final class DropDown: UIView { didSet { reloadAllComponents() } } + /** + Changing the text lines automatically reloads the drop down. + + Default - 1 + */ + @objc public dynamic var numberOfLines = DPDConstant.UI.NumblerOfLines { + didSet { reloadAllComponents() } + } + /** The NIB to use for DropDownCells @@ -1075,6 +1084,7 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { cell.optionLabel.textColor = textColor cell.optionLabel.font = textFont + cell.optionLabel.numberOfLines = numberOfLines cell.selectedBackgroundColor = selectionBackgroundColor cell.highlightTextColor = selectedTextColor cell.normalTextColor = textColor @@ -1088,6 +1098,14 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { customCellConfiguration?(index, dataSource[index], cell) } + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return UITableView.automaticDimension + } + + 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 }