Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom height capability to drop down #236

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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,11 @@ public final class DropDown: UIView {
didSet { setNeedsUpdateConstraints() }
}

// The height of the drop down
public var height: CGFloat = 0.0 {
didSet{ setNeedsUpdateConstraints() }
}

/**
arrowIndication.x

Expand Down Expand Up @@ -569,7 +574,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 @@ -1019,7 +1024,11 @@ extension DropDown {

/// Returns the height needed to display all cells.
fileprivate var tableHeight: CGFloat {
return tableView.rowHeight * CGFloat(dataSource.count)
if height == 0.0 {
return tableView.rowHeight * CGFloat(dataSource.count)
} else {
return height
}
}

//MARK: Objective-C methods for converting the Swift type Index
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 to drop down
dropDownLeft.height = 160
```

Display actions:
Expand Down