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

Height of the pop up #34

Open
hwainam opened this issue Aug 17, 2016 · 19 comments · May be fixed by #236
Open

Height of the pop up #34

hwainam opened this issue Aug 17, 2016 · 19 comments · May be fixed by #236
Assignees

Comments

@hwainam
Copy link

hwainam commented Aug 17, 2016

Is it possible to set the height of the pop up?
i have 30 elements in the drop down, when the drop down is shown, it covers my whole screen.

Is there a way to display fixed height so that only a few item shown and user can scroll through it?

@kevin-hirsch
Copy link
Collaborator

Hello @hwainam, it's not possible to set a maximum height for the drop down at the moment, but that's not a bad idea :)
I'll add it when I find the time.

Thanks!

@tiagopigatto
Copy link

I have the same case, a lot of elements and the drop-down is huge. Is this feature being implemented?

@Nostuh
Copy link

Nostuh commented Sep 29, 2016

I would like this feature as well!

@yhelfronda
Copy link

Is this feature already implemented? I also need it.

@cody1024d
Copy link

@kevin-hirsch Was wondering if you'd be open to a PR for this? I've run into a scenario where I need this as well (being able to essentially set a max-height that is LESS than the full window's height).

Seems like it should be straight-forward enough to create, but let me know your thoughts!

@siyavash4812
Copy link

The implementation of this feature is quite easy. All you have to do is change "visibleHeight" in side the DropDown file to whatever size you need. If you need to see a sample i can upload my work

@nidhipatel92
Copy link

Hello, kevin-Hirsch I have to change visibleHeight of DropDown. Help for that. Thank you

@Theysn
Copy link

Theysn commented Nov 8, 2017

It's simple, in the DropDown class you will find a variable called tableHeight return the height of the tableView. You can change it by this code, also search for tableView.isScrollEnabled and comment this line (line 482).

 if tableView.numberOfRows(inSection: 0) < 5 {
            return tableView.rowHeight * CGFloat(dataSource.count)
        }
        else {
            return 400
        }

@annjawn
Copy link

annjawn commented Jan 7, 2018

Here's my solution in DropDown.swift class-

Declared

public var dropDownHeight: CGFloat = 0.0 {
        didSet { setNeedsUpdateConstraints() }
    }

and then modified this

fileprivate var tableHeight: CGFloat {
        if dropDownHeight == 0.0{
            return tableView.rowHeight * CGFloat(dataSource.count)
        }else{
            return dropDownHeight
        }
}

usage is simply dropDown.dropDownHeight = //your height here in your view controller. If you define a height it will use that height else it will use the internally calculated height. This is working for me. However, be aware that putting a fixed height will only cause the dropdown to fit only a the number of cells that fit within the height i.e. it will not scroll.

@derekjcarter
Copy link

Hey everyone.. I have a slightly different solution that preserves the scrolling of the tableView with a smaller tableView size.

Declare dropDownHeight like annjawm added.

  public var dropDownHeight: CGFloat = 0.0 {
      didSet { setNeedsUpdateConstraints() }
  }

Instead of updating the tableHeight property, update the constraints instead. Replace updateConstraints() method with the following:

   public override func updateConstraints() {
        if !didSetupConstraints {
            setupConstraints()
        }
        
        didSetupConstraints = true
        
        let layout = computeLayout()
        
        if !layout.canBeDisplayed {
            super.updateConstraints()
            hide()
            return
        }
        
        xConstraint.constant = layout.x
        yConstraint.constant = layout.y
        widthConstraint.constant = layout.width
        
        // Change height of dropdown
        if dropDownHeight > 0 && dropDownHeight <= layout.visibleHeight {
            heightConstraint.constant = dropDownHeight
        } else {
            heightConstraint.constant = layout.visibleHeight
        }
        
        // Enable scrolling if offscreen content or dropdown height is set
        tableView.isScrollEnabled = layout.offscreenHeight > 0 || dropDownHeight > 0
        
        DispatchQueue.main.async { [weak self] in
            self?.tableView.flashScrollIndicators()
        }
        
        super.updateConstraints()
   }

Hope this is helpful... 👍

@gizemfitoz gizemfitoz linked a pull request May 29, 2019 that will close this issue
@HirakCTS
Copy link

Hi derekjcarter ,
I have used your solution, it did work but little issue is dropdown starts at the top of the MainWindow not from the top or bottom offset of sourceView.

Please help

@derekjcarter
Copy link

@Hirak-CTS, My solution didn't really change the anchorView or location where it's set. You might be working with an older version if you're setting sourceView. Setting anchorView of the DropDown object should handle which object to anchor the dropdown to. You can set the offset of the DropDown object as well.

@narendra-ct
Copy link

narendra-ct commented Nov 25, 2019

@kevin-hirsch @SticklyMan : Any update on this ??

@EKOLX
Copy link

EKOLX commented Oct 26, 2020

There is no Height property currently. If there is, please add to README.

@NortromInsanlyDev
Copy link

Hey everyone.. I have a slightly different solution that preserves the scrolling of the tableView with a smaller tableView size.

Declare dropDownHeight like annjawm added.

  public var dropDownHeight: CGFloat = 0.0 {
      didSet { setNeedsUpdateConstraints() }
  }

Instead of updating the tableHeight property, update the constraints instead. Replace updateConstraints() method with the following:

   public override func updateConstraints() {
        if !didSetupConstraints {
            setupConstraints()
        }
        
        didSetupConstraints = true
        
        let layout = computeLayout()
        
        if !layout.canBeDisplayed {
            super.updateConstraints()
            hide()
            return
        }
        
        xConstraint.constant = layout.x
        yConstraint.constant = layout.y
        widthConstraint.constant = layout.width
        
        // Change height of dropdown
        if dropDownHeight > 0 && dropDownHeight <= layout.visibleHeight {
            heightConstraint.constant = dropDownHeight
        } else {
            heightConstraint.constant = layout.visibleHeight
        }
        
        // Enable scrolling if offscreen content or dropdown height is set
        tableView.isScrollEnabled = layout.offscreenHeight > 0 || dropDownHeight > 0
        
        DispatchQueue.main.async { [weak self] in
            self?.tableView.flashScrollIndicators()
        }
        
        super.updateConstraints()
   }

Hope this is helpful... 👍

It's doesn't work now. It makes app crash. Anyone knows the reason and solution?

It's crash log
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSMethodSignature getArgumentTypeAtIndex:]: index (2) out of bounds [0, 1]'

@emreagball
Copy link

You can use bottom dropDown.offsetFromWindowBottom. It works some cases.

@vuralcelik
Copy link

vuralcelik commented Apr 18, 2021

You can use bottom dropDown.offsetFromWindowBottom. It works some cases.

If you set this property like that, it will not work properly.
dropDown.offsetFromWindowBottom = 100

But if you set the direction also, it will work like a charm.

dropDown.direction = .bottom
dropDown.offsetFromWindowBottom = 100

@ashrafkvt
Copy link

You can use bottom dropDown.offsetFromWindowBottom. It works some cases.

If you set this property like that, it will not work properly. dropDown.offsetFromWindowBottom = 100

But if you set the direction also, it will work like a charm.

dropDown.direction = .bottom
dropDown.offsetFromWindowBottom = 100

This is not working on iPad in landscape mode. Can you guys please check?

Is there any new direct method available for specifying the drop-down height?

algamza pushed a commit to algamza/DropDown that referenced this issue Jun 20, 2024
@Sridhar123985
Copy link

Hey everyone.. I have a slightly different solution that preserves the scrolling of the tableView with a smaller tableView size.

Declare dropDownHeight like annjawm added.

  public var dropDownHeight: CGFloat = 0.0 {
      didSet { setNeedsUpdateConstraints() }
  }

Instead of updating the tableHeight property, update the constraints instead. Replace updateConstraints() method with the following:

   public override func updateConstraints() {
        if !didSetupConstraints {
            setupConstraints()
        }
        
        didSetupConstraints = true
        
        let layout = computeLayout()
        
        if !layout.canBeDisplayed {
            super.updateConstraints()
            hide()
            return
        }
        
        xConstraint.constant = layout.x
        yConstraint.constant = layout.y
        widthConstraint.constant = layout.width
        
        // Change height of dropdown
        if dropDownHeight > 0 && dropDownHeight <= layout.visibleHeight {
            heightConstraint.constant = dropDownHeight
        } else {
            heightConstraint.constant = layout.visibleHeight
        }
        
        // Enable scrolling if offscreen content or dropdown height is set
        tableView.isScrollEnabled = layout.offscreenHeight > 0 || dropDownHeight > 0
        
        DispatchQueue.main.async { [weak self] in
            self?.tableView.flashScrollIndicators()
        }
        
        super.updateConstraints()
   }

Hope this is helpful... 👍

this worked

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

Successfully merging a pull request may close this issue.