Emojis messing with obj-c's sizeWithFont math

前端 未结 3 680
青春惊慌失措
青春惊慌失措 2021-02-01 07:10

In a UITableView that needs to display a long list of chatlike conversations, often containing emojis, a size calculation error occurs.

My problem is, that

3条回答
  •  不思量自难忘°
    2021-02-01 07:42

    I am use UILabel

    sizeThatFits(_ size: CGSize) -> CGSize

    It work for me.

    my code

    let tempLabel = UILabel()
    tempLabel.font = font
    tempLabel.attributedText = attText
    tempLabel.numberOfLines = 0
    let size = tempLabel.sizeThatFits(CGSize(width: 200, height:CGFloat.greatestFiniteMagnitude))
    

    as the code, you need to assign three property.

提交回复
热议问题