使用AttributedString截断跟踪

时间:2017-06-09 10:54:30

标签: swift uilabel

我在单元格中有一个UILabel,我在其中设置了属性文本。它归因于文字太大而不应该......最后。怎么做?

1 个答案:

答案 0 :(得分:1)

func addTitle(title: String) {
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineBreakMode = .byTruncatingTail
    let attributedTitle = NSAttributedString(string: title, attributes: [NSParagraphStyleAttributeName: paragraphStyle])
    self.titleLabel.attributtedString = attributedTitle
}