I am trying to make a UILabel within a static UITableViewCell multiline depending on its content, which changes.
In the viewDidLoad
method, I have the code that initialises the text within the label, shortly followed by:
cellLabel.text = "Here is some text, but because of how long it is, it has to span a number of lines."
cellLabel.numberOfLines = 0
cellLabel.sizeToFit()
tableViewCell.textLabel?.sizeToFit()
tableViewCell.textLabel?.numberOfLines = 0
tableViewCell.textLabel?.lineBreakMode = .ByWordWrapping
And then I am attempting to calculate the height that the row must be in order to accomodate the multiline label:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if (indexPath.section == 2 && indexPath.row == 0) {
return cellLabel.frame.height
}
else {
return 44
}
}
However, what is returned is a multiline UITableViewCell but the ending of the text is cut off and isn't displayed. I would add a value to the end of return definitionLabel.frame.height, however the content of the label varies.
Could someone please let me know how I simply have a multiline UILabel within a static UITableViewCell using Swift 2.0 and iOS 9.
Note: I have added:
tableView.rowHeight = UITableViewAutomaticDimension
And I am using a basic static table view cell which has applied constraints by default.