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?
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
Call [view layoutIfNeeded]
after set the text of UILabel. It will layout subviews again.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With