You can add a UIScrollView
. On top of it add a UITableView
with scrollingEnabled = false
.
Knowing the number of cells in the tableView and the height of each row, you can calculate the UITableView
total height and set the scrollView's contentSize
accordingly.
If you are trying to keep the height of the tableview constant regardless of whether you have 1 cell or 10 cells, then you need to make your cell height be dynamic, and change it based on the number of cells you have (height = available_height / numberOfCells).
Usually cell height is fixed, or it is dynamic like the cells in the Messages app, and that is done by manipulating:
- tableView:heightForRowAtIndexPath:
- tableView:estimatedHeightForRowAtIndexPath:
If you are not trying to keep the tableView a constant height, then you should still use the above methods to make the cells take up the appropriate amount of space to allow the tableView not to need scrolling, and then you will have to readjust the size of the tableView to pull the bottom up.
AutoLayout won't do this for you automatically, as far as I know. There are tricks to make AutoLayout be more aware of the size of your objects, such as adding
-intrinsicContenSize
That might be overkill for what you are doing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.