Skip to content

Conversation

dev-Siddhesh
Copy link

@dev-Siddhesh dev-Siddhesh commented Jun 20, 2022

In pod file DropDown.swift do following changes for custom height

Step 1 : Add this below width property

public var height: CGFloat? {
       didSet { setNeedsUpdateConstraints() }
 }

Step 2 : In public override func updateConstraints() do this

replace 
`heightConstraint.constant = layout.visibleHeight `
with following

if let height = self.height {
    if layout.visibleHeight >= height {
         heightConstraint.constant = self.height ?? layout.visibleHeight
     } else {
         heightConstraint.constant = layout.visibleHeight
     }
} else {
     heightConstraint.constant = layout.visibleHeight
}

Step 3 : In fileprivate func computeLayoutForTopDisplay(window: UIWindow) -> ComputeLayoutTuple do this

replace

if y < windowY {
    offscreenHeight = abs(y - windowY)
    y = windowY
}

with following

if y < windowY {
 offscreenHeight = abs(y - windowY)
  if let height = self.height {
         y = anchorViewMaxY + topOffset.y - height
    } else {
          y = windowY
    }
 }

Uses

let dropDown = DropDown()
dropDown.height = 50

If height is not set, the dropdown height will be its content size and if content size is greater than screen/superview size then it will stop at view bounds and dropdown's scroll is activated.
If you don't want that set height as suggested above.
After setting height:-

  1. if your content size is less than your assigned height it will wrap to its content means dropdown will have height of its content size, you will see all dropdown option in list.
  2. If content size exceeds assigned height then dropdown will have its assigned height and scroll will be activated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants