I have a label in a tableview cell, the content of which changes all the time. I want the label to show all the content. I have tried setting Numberoflines as 0, but it doesn't work. But if i reduce the font size to around 10, it works. Is there any way to do so without reducing font size? I already tried https://stackoverflow.com/a/990244/6602495, but no result as expected.
-
Please upload a screen shot of your tableview – Mudith Chathuranga Silva Sep 19 '16 at 11:24
-
Have you created a custom cell ? If yes then show the constaints for the label. – Umair Afzal Sep 19 '16 at 11:25
-
I have given left, right, top, & bottom constraints. – Sneha Sep 19 '16 at 11:57
3 Answers
UILabel will render as in the question that you quoted if there are no constrains or frame is set properly.
So you must come to those conditions. If you have added constrains or set the frame, then change that code. If that happens in the default cell template then you have to subclass it and add either change label's frame on Layout subviews or add another label and use it.

- 9,672
- 5
- 36
- 57
Only add this property on UILabel instance like this.
yourLabel.adjustsFontSizeToFitWidth = true

- 651
- 5
- 16
-
I want a fixed font size of bold 16. How can I achieve that with this property? – Sneha Sep 20 '16 at 04:31
First of all you have to set the number of lines to 0 as you correctly did, then you have to set all the correct constraints for the label inside your tableview cell except for the height so it can change, finally you have to programmatically set two properties in the viewDidLoad of your tableview class to make the cell resizable if needed: tableView.estimatedRowHeight
equals to the height of your cell and tableView.rowHeight = UITableViewAutomaticDimension
.

- 126
- 2
- 12
-
Can you please post a screenshot of your cell and the code you are using? – Federico Milani Sep 20 '16 at 07:26