cell.bodyText.numberOfLines = 0
cell.bodyText.text = newsBody
cell.bodyText.sizeToFit()
I set the number of lines to 0 because the number of lines can vary (I am retrieving news articles and since every news article is obviously different in length, numberOfLines is 0)
If I do not use sizeToFit()
after assinging newsBody
to the label, and check the label height (cell.bodyText.frame.size.height)
, I get really large numbers (when I tested it, an article that had 25 lines of text, the height was apparently 4000). If I use sizeToFit
and then check the height, I get 21 no matter how short or long the label is. (21 is the height I set the UILabel in the storyboard).
How can I get an accurate representation of how many lines are in the UILabel or even just the height of the label?