'Swift Autolayout headerview in UITableView
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.
In this screenshot is shown only 1 line. Constraints are set as:
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
Solution 1:[1]
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.
Solution 2:[2]
Try Setting Lines to “0” and Line Breaks To “word wrap”
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | nicksarno |
Solution 2 | Aakash Verma |