UITableView dynamic cell heights only correct after some scrolling

后端 未结 24 1272
误落风尘
误落风尘 2020-11-29 16:41

I have a UITableView with a custom UITableViewCell defined in a storyboard using auto layout. The cell has several multiline UILabels.

24条回答
  •  青春惊慌失措
    2020-11-29 17:20

    I have the issue with resizing label so I nee just to do
    chatTextLabel.text = chatMessage.message chatTextLabel?.updateConstraints() after setting up the text

    // full code

    func setContent() {
        chatTextLabel.text = chatMessage.message
        chatTextLabel?.updateConstraints()
    
        let labelTextWidth = (chatTextLabel?.intrinsicContentSize().width) ?? 0
        let labelTextHeight = chatTextLabel?.intrinsicContentSize().height
    
        guard labelTextWidth < originWidth && labelTextHeight <= singleLineRowheight else {
          trailingConstraint?.constant = trailingConstant
          return
        }
        trailingConstraint?.constant = trailingConstant + (originWidth - labelTextWidth)
    
      }
    

提交回复
热议问题