AutoLayout row height miscalculating for NSAttributedString

后端 未结 8 1635
时光取名叫无心
时光取名叫无心 2021-01-31 11:57

My app pulls HTML from an API, converts it into a NSAttributedString (in order to allow for tappable links) and writes it to a row in an AutoLayout table. Trouble i

8条回答
  •  逝去的感伤
    2021-01-31 12:38

    You need to update intrinsic content size.

    I assume that you set attributed text to label in this code [self configureContentCellForIndexPath:cell atIndexPath:indexPath];

    So, it should look like this

    cell.youLabel.attributedText = NSAttributedString(...) 
    cell.youLabel.invalidateIntrinsicContentSize()
    cell.youLabel.layoutIfNeeded()
    

    You height calculation code (CGFloat)textViewHeightForAttributedText:(NSAttributedString*)text andFont:(UIFont *)font andWidth:(CGFloat)width should be replaced with cell height calculation using prototyping cell.

提交回复
热议问题