没有左右对齐的时候是这样的:

设置之后是这样的:

实现起来很简单
let paragraphStyle = NSMutableParagraphStyle()
//这个是对齐方式设置,设置这个属性就可以实现了
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
网友评论