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

Change the DropDown height #225

Open
ghost opened this issue Feb 23, 2019 · 5 comments
Open

Change the DropDown height #225

ghost opened this issue Feb 23, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 23, 2019

I am using Swift 4.2

How can I change the DropDown height here?
I have tried this: #34 (comment)
But those answers just makes my app crashes.

@Tabassumbanu786
Copy link

i am facing same issue .please suggest a solution

@omerbaskurt
Copy link

I was having the same problem. Cleaning the build folder and then compiling solved it

@RuttabHaroon
Copy link

RuttabHaroon commented Oct 30, 2019

Since the drop down height is set according to the height of cell multiplied by the number of cells. You can try changing the height of the cells dynamically by doing the following:

in the DropDown.swift file add the following function

public func dynamicChange(height toValue: CGFloat) {
        tableView.rowHeight = toValue
 }

Now, just call this function after intializing dropDown instance. Example:

let dropDown = DropDown()
 dropDown.dynamicChange(height : "INSERT THE HEIGHT YOU WANT") 

OR, if you want to dynamically change the height of a particular cell you can do this:

dropDown.cellConfiguration = { [unowned self] (index, item) in
   if index == 0 {
        dropDown.dynamicChange(height : "INSERT THE HEIGHT YOU WANT") 
   }
   return "- \(item) (option \(index))"
}

@InfinyWebcom
Copy link

InfinyWebcom 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

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

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 it will stop at view bounds and dropdown's scroll is activated.
If you don't want that set height as suggested above : 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.
If content size exceeds assigned height then dropdown will have its assigned height and scroll will be activated.

@thesurajrai
Copy link

i am facing same issue .please suggest a solution

#225 (comment)

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

No branches or pull requests

5 participants