Swift: 我可以调整带有动态字体大小的属性文本吗?

Swift: Can I adjust attributed text with dynamic font size?

我正在使用 collectionView 每个单元格的内容如下:

一切正常,直到我在 iphone 5s 上测试它:

"Ho Chi Minh City" 超出范围。 这是我的代码:

func configureNameLabel() {
    nameLabel.numberOfLines = 2
    let attributedText = NSMutableAttributedString(string: post?.name ?? "", attributes: [.font: UIFont.boldSystemFont(ofSize: 15)])
    attributedText.append(NSAttributedString(string: "\nSaturday, December 1, 2018 ⦁ Ho Chi Minh City ⦁ ", attributes:
        [.foregroundColor: UIColor.lightGray, .font: UIFont.preferredFont(forTextStyle: .caption1)]))

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 5
    attributedText.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: attributedText.string.count))

    let attachment = NSTextAttachment()
    attachment.image = UIImage(named: "user-male")
    attachment.bounds = CGRect(x: 0, y: -2, width: 12, height: 12)
    attributedText.append(NSAttributedString(attachment: attachment))

    nameLabel.attributedText = attributedText
}

我认为这个问题是由字体大小引起的,有人可以解决这个问题吗?

谢谢大家,我解决了。 "label.numberOfLines = 0" 成功了。问题出在我的限制上。