Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions DropDown/src/DropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public final class DropDown: UIView {
didSet { setNeedsUpdateConstraints() }
}

/**
The visible amout of cells.
*/
public var visibleCellCount: Int? {
didSet { setNeedsUpdateConstraints() }
}
/**
arrowIndication.x

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down