0

We have the following UI in Xcode using IB. Essentially there is a TableView. The TableView has four rows inside the Content View - these are not table rows.

-- TableView
    -- StackView
        -- DateLabel (Row 1)
        -- StackView - Time and Category (Row 2)
              -- Timelabel
              -- Category label
        -- CategoryDetailLabel (Row 3)
        -- MoreLabel (Row 4)

We want the UILabel (CategoryDetailLabel) in Row 3 to expand dynamically based on the content. So based on documentation here we turned on the "Row Height" and "Estimated Height" on the TabelView to be automatic.

enter image description here

But Unfortunately only one row (line) gets displayed enter image description here

When we change the row height on tableview to 150 we get all the rows to display

enter image description here

But the CategoryDetaillabel does not expand its height. The content gets truncated. enter image description here

We have set the "Lines" of CategoryDetailLabel to 0. How do we fix this using IB.

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
Jack tileman
  • 813
  • 2
  • 11
  • 26
  • Hi Jack, let me know if this helps - https://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights – shbedev Nov 16 '19 at 16:01

1 Answers1

1

1 - Constraint the UILabel to all edges of the cell.

2 - add this code to your table view.

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 44

3 - don't use a height for row.

youssef mostafa
  • 308
  • 2
  • 11
  • And be sure to set the `numberOfLines` property of the label to 0, so that it adjusts dynamically to the amount of text to be displayed. – Duncan C Nov 18 '19 at 00:14