gpt4 book ai didi

swift - 如何使用 setAttributedText 为 WKInterface 标签设置对齐方式

转载 作者:搜寻专家 更新时间:2023-10-31 22:22:49 24 4
gpt4 key购买 nike

我正在尝试使用 setAttributedText 函数为 WKInterfaceLabel 设置对齐方式。这是我的代码:

 var paragraphStyle = NSParagraphStyle.defaultParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Center
var attributedDictonary = [NSForegroundColorAttributeName:UIColor.greenColor(), NSParagraphStyleAttributeName:paragraphStyle]
var attributeString = NSAttributedString(string: "TextAttributed", attributes: attributedDictonary)
self.titleLabel.setAttributedText(attributeString)

但是我遇到了这一行的问题:

paragraphStyle.alignment = NSTextAlignment.Center

我收到错误:无法分配给“paragraphStyle”中的“alignment”

如何使用 setAttributedTextWKInterfaceLabel 设置对齐?

最佳答案

你需要使用NSMutableParagraphStyle:

var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.CenterTextAlignment

关于swift - 如何使用 setAttributedText 为 WKInterface 标签设置对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29742863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com