中心certificateUILabel文本?
我试图中心certificate我的UILabel的文字像图片:
我的代码示例:
myLabel.textAlignment = .Justified myLabel.lineBreakMode = .ByWordWrapping
结果我有:
我错过了什么 ?
我find了答案: https : //stackoverflow.com/a/27548566/833816
它的工作原理是添加paragraphStyle.firstLineHeadIndent = 0.001
全样本:
let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .Justified paragraphStyle.firstLineHeadIndent = 0.001 let mutableAttrStr = NSMutableAttributedString(attributedString: detailsLabel.attributedText) mutableAttrStr.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, mutableAttrStr.length)) myLabel.attributedText = mutableAttrStr
尝试
myLabel.textAlignment = NSTextAlignment.Center