I have given the leading and trailing to textview inside content of tableview . I want to dynamically calculate the height of Tableviewcell. the height calculation is working fine sometimes but sometimes not working particular devices like 5c.
i have used following code to estimate the height of text :
func estimateFrameForText(text: String) -> CGRect {
let size = CGSize(width: self.view.frame.size.width, height: 10000000)
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
return NSString(string: text).boundingRect(with: size, options: options, attributes: [NSFontAttributeName: UIFont.init(name: FontStyle.FontName.kDefault, size: 15.0)!], context: nil)
}
The important thing here is the text is HTML text, I have converted it into plain text. then that plain text is passed to above functions.
Set automatic row height calculation using below methods of table view
func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat
{
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
{
return 100
}