0

I am fighting with auto layout in iOS. I want to make the label in the picture above change the height of the cell and expand to show all text in the label. By default it is set to 3 lines and truncate tail for wrapping.

I have UITableViewAutomaticDimension set and estimatedHeightRow set as well. I tried to change label lines to 0 and call sizeToFit() however it did not work as expected (label remains unchanged).

Also picture in the screenshot might be available or not depending on the response from the server and it may be removed from the superview.

Any ideas? What am I missing?

Cell layout

UPD: Below are constraints for the label, see more button and image.

Label constraints

Image constraints

See more constraints

Oleg Novosad
  • 2,261
  • 1
  • 27
  • 28
  • 1
    On tapping see more consider reloading the specific cell after setting numberOf lines to 0. Finally for imageView if u don't add any height constraint imageView will take the height based on the image being set and content mode set. So if image is not there its frame becomes 0 so u don't have to do anything about that – Sandeep Bhandari Sep 14 '17 at 14:08
  • @SandeepBhandari Thanks. I've tried it and did not work =( even when I set numberOfLines to 0 in interface builder views are not moving to the bottom. Any suggestions? – Oleg Novosad Sep 14 '17 at 14:15
  • 1
    Try setting the ContentCompressionResistancePriority of textView to high (1000) and set the number of lines to 0 in interface builder. That way ur textView will expand with text and some other view will either result in auto layout break or will be compressed then u can figure out whats messing up with ur view – Sandeep Bhandari Sep 14 '17 at 14:20
  • 1
    @Array - you may find this helpful... https://stackoverflow.com/a/43096940/6257435 – DonMag Sep 14 '17 at 14:25

1 Answers1

1

After you set number of lines in the label to 0, use following to redraw the tableView:

tableView?.beginUpdates()
tableView?.setNeedsDisplay()
tableView?.endUpdates()
Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90