0

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.

Community
  • 1
  • 1
Sneha
  • 2,200
  • 6
  • 22
  • 36

3 Answers3

0

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.

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57
0

Only add this property on UILabel instance like this.

    yourLabel.adjustsFontSizeToFitWidth = true
Sumit Jangra
  • 651
  • 5
  • 16
0

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.

Federico Milani
  • 126
  • 2
  • 12