From 93ed5f3f7c759dd0adf49872eefcdb7f2bacecb0 Mon Sep 17 00:00:00 2001 From: Alexandra Kondratjeva Date: Thu, 22 Dec 2022 21:53:53 +0200 Subject: [PATCH] Added support for numberOfLines and its setting By default numberOfLines = 1 --- DropDown/helpers/DPDConstants.swift | 1 + DropDown/src/DropDown.swift | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/DropDown/helpers/DPDConstants.swift b/DropDown/helpers/DPDConstants.swift index 52047beb..5a717599 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 f41e8ddd..dac9a284 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 }