设置指定行数:
label.numberOfLines = 2
超出两行后,以省略号结尾:
let paragraphStyle = NSMutableParagraphStyle.init()
paragraphStyle.lineSpacing = 4.0//行间距
paragraphStyle.lineBreakMode = .byTruncatingTail//以省略号结尾
let attStr = NSMutableAttributedString.init(string: "哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈")
attStr.addAttributes([.font: UIFont.systemFont(ofSize: 15.0), .foregroundColor: UIColor.black, .paragraphStyle: paragraphStyle], range: NSRange(location: 0, length: attStr.length))
label.attributedText = attStr
网友评论