[英]Swift 4 Align attributed text to center in label
如何在中心对齐AttributedText?
到目前为止的代码:
extension String { var atributedText: NSMutableAttributedString { let style = NSMutableParagraphStyle() style.alignment = NSTextAlignment.center guard let data = self.data(using: String.Encoding.utf8) else { return NSMutableAttributedString() } guard let attrStr = try? NSMutableAttributedString( data: data, options: [NSMutableAttributedString.DocumentReadingOptionKey.documentType: NSMutableAttributedString.DocumentType.html], documentAttributes: nil) else { return NSMutableAttributedString() } attrStr.addAttribute(.paragraphStyle, value: style, range: NSMakeRange(0, attrStr.length)) return attrStr } }
文本在中心但垂直扩展了,但是如何垂直和水平对齐? 谢谢。
我发现我做错了。 我没有将label.bottom设置为cell.bottom约束。 因此,当我将最高约束条件更改为5时,标签始终位于最高位置,并且没有展开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.