沒有左右對齊的時候是這樣的:
設置之后是這樣的:
實現(xiàn)起來很簡單
let paragraphStyle = NSMutableParagraphStyle()
//這個是對齊方式設置涩澡,設置這個屬性就可以實現(xiàn)了
paragraphStyle.alignment = NSTextAlignment.justified
//設置行間距
paragraphStyle.lineSpacing = 6
let content : String = "我是王閩航"
let contentStr : NSMutableAttributedString = NSMutableAttributedString(string: content)
contentStr.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, content.count))
self.contentLabel.attributedText = contentStr