UITableView: automatically set height for the row and fix it with max height constant

Bogdan Bogdanov

I need automatically set the height for the row. I use

theTable.estimatedRowHeight = 60
theTable.rowHeight = UITableViewAutomaticDimension

but the height is not fixed. I need fixed height something like MAX 60 height, by default height is 40. With estimatedRowHeight the height is not fixed and when the string is long the cell takes all screen. How to fix it?

Zell B.

You will need to put all the content of table view cell in a single view (lets call it MainView) and set MainView top, leading and trailing edge constrains to container view. Also set a height constraint less than or equal to 60 with required priority. After that put your label in MainView set top, leading and trailing constrains to MainView and a bottom space to MainView constraint with high priority. Also on your label set number of lines to 0 and preferred width to explicit. This way if label content height is less than 60, MainView will shrink and that will still match height constraint of less than or equal to 60. Otherwise if content height is greater then 60 the bottom space to MainView constraint will break without causing problems since its priority is less then MainView height constraint.

Finally override tableview delegate methods as follow

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
   return UITableViewAutomaticDimension
}

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 40
} 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set max height of Adsense responsive ad unit

From Dev

Set row height depend on JTextArea height

From Dev

How to set row height of QTableView?

From Dev

Set row height of a UITableView according to the cell in that row

From Dev

uitableview autoscrolling when I programatically set the height

From Dev

How to automatically set row height in NSOutlineView to fit text?

From Dev

How to set the container height automatically maintaining the ratio

From Dev

How to set max height of a picture in crystal report?

From Dev

UITableView default row height Xcode

From Dev

UITableView deleting row reduced table row height

From Dev

CSS Table set max row height

From Dev

How to set max height for Bootstrap accordion

From Dev

Set height of UITableView which contain dynamic Cell Height

From Dev

Dynamic UITableView row height using UIStackView?

From Dev

How to set height constraint of UITableView according to dynamic height cells?

From Dev

RecycleView row max height?

From Dev

How to dynamically set the height of a UITableView?

From Dev

ddslick set Max height

From Dev

How to set height of UITableView to solve scrolling issue?

From Dev

CSS - Automatically set height of container?

From Dev

How to automatically set different item height in ExpandableListView?

From Dev

How to resize the UITableView row height in Objective C

From Dev

Unable to set row height equal to table height

From Dev

Automatically max-height in JS

From Dev

Accessing the Row Height in Dynamic UITableView Prototypes

From Dev

How to set height of UITableView programatically

From Dev

Set height of a specific cell in my UITableView

From Dev

How to set Dynamically UITableView height in Swift?

From Dev

How to resize the row height of a UITableView automatically in xamarin ios

Related Related

  1. 1

    Set max height of Adsense responsive ad unit

  2. 2

    Set row height depend on JTextArea height

  3. 3

    How to set row height of QTableView?

  4. 4

    Set row height of a UITableView according to the cell in that row

  5. 5

    uitableview autoscrolling when I programatically set the height

  6. 6

    How to automatically set row height in NSOutlineView to fit text?

  7. 7

    How to set the container height automatically maintaining the ratio

  8. 8

    How to set max height of a picture in crystal report?

  9. 9

    UITableView default row height Xcode

  10. 10

    UITableView deleting row reduced table row height

  11. 11

    CSS Table set max row height

  12. 12

    How to set max height for Bootstrap accordion

  13. 13

    Set height of UITableView which contain dynamic Cell Height

  14. 14

    Dynamic UITableView row height using UIStackView?

  15. 15

    How to set height constraint of UITableView according to dynamic height cells?

  16. 16

    RecycleView row max height?

  17. 17

    How to dynamically set the height of a UITableView?

  18. 18

    ddslick set Max height

  19. 19

    How to set height of UITableView to solve scrolling issue?

  20. 20

    CSS - Automatically set height of container?

  21. 21

    How to automatically set different item height in ExpandableListView?

  22. 22

    How to resize the UITableView row height in Objective C

  23. 23

    Unable to set row height equal to table height

  24. 24

    Automatically max-height in JS

  25. 25

    Accessing the Row Height in Dynamic UITableView Prototypes

  26. 26

    How to set height of UITableView programatically

  27. 27

    Set height of a specific cell in my UITableView

  28. 28

    How to set Dynamically UITableView height in Swift?

  29. 29

    How to resize the row height of a UITableView automatically in xamarin ios

HotTag

Archive