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

Can't get cells to size to appropriate height #1

Closed
gereons opened this issue Jun 10, 2020 · 3 comments
Closed

Can't get cells to size to appropriate height #1

gereons opened this issue Jun 10, 2020 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@gereons
Copy link

gereons commented Jun 10, 2020

Hi, I just came across this pod as I have a layout that requires side-by-side cells to have equal heights. Unfortunately I can't get it to work correctly, even in a simple examples where cells contain two labels of variably-sized text. For example, in this screenshot

rowheight

all cells starting from the 3rd row are way too small.

https://github.com/gereons/RowHeightTest contains a demo project that illustrates this.

Is this a bug, or am I using the pod incorrectly?

@rwbutler rwbutler added the help wanted Extra attention is needed label Jun 10, 2020
@rwbutler
Copy link
Owner

I think what you need here is to be able to calculate the height of a cell knowing that the width of that cell is fixed (because the columns will have a fixed width based on the number of columns you have specified there should be - in this case 2). Therefore rather than:

let size = cell.contentView.systemLayoutSizeFitting(
            UIView.layoutFittingCompressedSize,
            withHorizontalFittingPriority: .defaultHigh,
            verticalFittingPriority: .defaultLow
)

Try:

let size = cell.contentView.systemLayoutSizeFitting(
                   CGSize(width: layout.columnWidth(), height: UIView.noIntrinsicMetric),
                   withHorizontalFittingPriority: .required,
                   verticalFittingPriority: .defaultLow
)

This should calculate a size fitting the cell's constraints with the additional constraint that the width of the cell is fixed meaning that the height of the cell may now be accurately determined. Hope this helps!

@gereons
Copy link
Author

gereons commented Jun 11, 2020

Fantastic, that works exactly like I want it to. Thank you!

@gereons gereons closed this as completed Jun 11, 2020
@rwbutler
Copy link
Owner

No problem - glad it helped! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants