AutoLayout row height miscalculating for NSAttributedString

后端 未结 8 1772
时光取名叫无心
时光取名叫无心 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:27

    I'm assuming you are using a UILabel to display the string?

    If you are, I have had countless issues with multiline labels with autoLayout. I provided an answer here

    Table View Cell AutoLayout in iOS8

    which also references another answer of mine that has a breakdown of how i've solved all my issues. Similar issues have cropped up again in iOS 8 that require a similar fix in a different area.

    All comes down to the idea of setting the UILabel's preferredMaxLayoutWidth every time is bounds change. What also helped is setting the cells width to be the width of the tableview before running:

    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    

提交回复
热议问题