From e7023cb78ad5bc166bb37330babebf97255a687b Mon Sep 17 00:00:00 2001 From: Veronika Goreva Date: Wed, 9 Oct 2019 10:34:00 +0700 Subject: [PATCH] Add ability to show particular amount of dropDown cells. --- DropDown/src/DropDown.swift | 13 +++++++++++-- README.md | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index 25fa2b2..322d7fc 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -152,6 +152,12 @@ public final class DropDown: UIView { didSet { setNeedsUpdateConstraints() } } + /** + The visible amout of cells. + */ + public var visibleCellCount: Int? { + didSet { setNeedsUpdateConstraints() } + } /** arrowIndication.x @@ -569,7 +575,7 @@ extension DropDown { widthConstraint.constant = layout.width heightConstraint.constant = layout.visibleHeight - tableView.isScrollEnabled = layout.offscreenHeight > 0 + tableView.isScrollEnabled = true DispatchQueue.main.async { [weak self] in self?.tableView.flashScrollIndicators() @@ -697,7 +703,10 @@ extension DropDown { constraintWidthToFittingSizeIfNecessary(layout: &layout) constraintWidthToBoundsIfNecessary(layout: &layout, in: window) - let visibleHeight = tableHeight - layout.offscreenHeight + var visibleHeight = tableHeight - layout.offscreenHeight + if let visibleCellCount = self.visibleCellCount, CGFloat(visibleCellCount) * cellHeight <= visibleHeight, visibleCellCount != 0 { + visibleHeight = CGFloat(visibleCellCount) * cellHeight + } let canBeDisplayed = visibleHeight >= minHeight return (layout.x, layout.y, layout.width, layout.offscreenHeight, visibleHeight, canBeDisplayed, direction) diff --git a/README.md b/README.md index c423fe5..5e4adb3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,9 @@ dropDown.selectionAction = { [unowned self] (index: Int, item: String) in // Will set a custom width instead of the anchor view width dropDownLeft.width = 200 + +// Will set a custom height for dropDown +dropDownLeft.visibleCellCount = 3 ``` Display actions: