1

I'm trying to create a view that has some labels and a UITableView. First of all i tried to create a UIView => UIScrollview => UIView + UITableView After reading a lot i experienced problems with scrolls, 1 from the UIScrollView and 1 from the UITableView, so i decided to switch to the suggested approach of having: UIView => UITableView with headerview

Scroll works fine but now i have problems with Autolayout.

The header view have 2 labels. "LeftLabel" and "RightLabel". The RightLabel should have dynamic height and >= 21

In code i tried to add a text that won't fit in 1 line and with autolaout label should expand and use 2 o 3 lines to fit the text.

Screenshot of the problem

In this screenshot is shown only 1 line. Constraints are set as: Autolayout

I uploaded the demo proyect to github: https://github.com/Miguel86/UIViewAutolayoutExample/ Scroll works fine, but autolayout of the "headerview" not.

Any suggestion of where could be the problem?

[UPDATE] Solved using the approach explained in: https://github.com/aunnnn/TableHeaderViewWithAutoLayout

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Miguel
  • 558
  • 6
  • 21

2 Answers2

0

From my understanding, problem is that RightLabel isn't going to multiple lines? If so: go into storyboard, select the headerview and drag it down so it's Height is longer. I think there just wasn't enough room in the cell for the label to go to 2 lines.

nicksarno
  • 3,850
  • 1
  • 13
  • 33
  • Yes, but that is why i want to use autolayout. And if the text don't fit in 3 lines... – Miguel Jun 19 '20 at 05:59
  • Did you do what I said? I ran your project and it went on more than 3 lines. FYI - autolayout does not dynamically change the height of the header/cell. That is set when the tableview loads. – nicksarno Jun 19 '20 at 13:04
  • Yes i tested, i don't want in design more height, obviously if by default its height is enough to have 2 lines will work, but if the text requires 3 lines will fail another time. – Miguel Jun 22 '20 at 09:41
0

Try Setting Lines to “0” and Line Breaks To “word wrap”

  • Tested but doesn't work, you will only see 1 line with "This is a long text that won't fit" but the rest of the string is not displayed. – Miguel Jun 19 '20 at 06:01
  • I think the problem is not the label but the height of your header view. Check this out https://stackoverflow.com/questions/29462331/is-it-possible-to-obtain-a-dynamic-table-view-section-header-height-using-auto-l – Aakash Verma Jun 20 '20 at 16:33
  • Thanks @Aakash verma. finally i solved with this: https://github.com/aunnnn/TableHeaderViewWithAutoLayout – Miguel Jun 22 '20 at 09:43