I'm trying to set the UITableViewCell's Height depending on the height of a UILabel.
My problem is similar to this one.
But the OC code in that answer seems to been deprecated now(I'm not sure, just can't find it).
I'm using the following code to calculate the height of the label.
extension String {
// the length of text in one line
func size(ofFont font: UIFont) {
return (self as NSString).size(attributes: [NSFontAttributeName: font])
}
In cellForRow:
method:
let size = text.size(ofFont: font)
let height = ceil(size.width/(UIScreen.main.bounds.width))*size.height
But it would be additional break line if the last word is too long to display in one line.
So, here comes the bug.
Thank you for any suggestion.