Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIlabel multiline in UITableView

I have problem with UILabel in UITableView. I want to bring film's plot in UILabel, but when application started, I have just one line of non-full plot, but when I scroll down and up, I get full film's plot with 2-3 lines. What problem can be? When application start

When scrolled down and back to film

In UILabel preferences I choose 0 lines (It makes label is multiline). In ViewController, in "viewDidLoad" I wrote two line of code, to make cell resizable:

self.searchTableView.estimatedRowHeight = 44.0
self.searchTableView.rowHeight = UITableViewAutomaticDimension
like image 847
cmashinho Avatar asked Aug 26 '15 09:08

cmashinho


2 Answers

Call [view layoutIfNeeded] after set the text of UILabel. It will layout subviews again.

like image 127
tuledev Avatar answered Sep 20 '22 13:09

tuledev


With UILabel over multiple lines, you have to give it a hand to know when to wrap text during layout.

To do this you need to set the preferredMaxLayoutWidth property. See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILabel_Class/#//apple_ref/occ/instp/UILabel/preferredMaxLayoutWidth

So in your cellForRowAtIndexPath method add something like:

cell.yourUILabelIBOutlet.preferredMaxLayoutWidth = tableView.frame.size.width;
like image 37
Rory McKinnel Avatar answered Sep 17 '22 13:09

Rory McKinnel