B
B
boobooking2018-03-01 11:44:35
iOS
boobooking, 2018-03-01 11:44:35

How to make TableView height "float" but a multiple of a constant?

Tell me how you can implement such a configuration through AutoLayout or in code.
The application screen is divided into two parts - at the top is a header with text, below it is a UITableView table. In a table, the cell width is fixed (let's call this width X).
The header width will change, but there is a mandatory minimum, let's say 70. That is, the header width >= 70.
I want to implement that the table width is always (for any device variant) a multiple of the X cell width. For different device sizes, the table width will "float" ", but be sure that it always remains a multiple of X.
Accordingly, all the remaining space (which is not enough to accommodate another X cell) is automatically added to the width of the header above the table.
An example is in the picture.
5a97bd01a1350355639510.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Globak, 2018-03-03
@boobooking

yes, you can implement this. If I understand correctly, then in the text you need to replace all the words "Width" with "Height"?
There are only mathematical calculations
. You also need to understand what is your priority, the height of the X cell (70) or an even number of cells on the screen. Because both conditions may not match.
1) First, calculate how many X heights you have that will fit on the screen.
maxPossibleCellsNumberOnScreen = (screenHeight - statusBarHeight) / X
2) you bind the table (autolayout) to the bottom border in the code, and the table height = X * (number of cells)
But the number of cells should not exceed the number of maxPossibleCellsNumberOnScreen - 1 (place for the header)
3) Bind header from the top of the table to the top of the screen
But there is another nuance, if the table scrolls and its cell is perfectly hidden, then the user may not understand that the table can be scrolled.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question