微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法证明NSMutableAttributedString

如何解决无法证明NSMutableAttributedString

我使用NSMutableAttributedString已有一段时间了,直到现在再也没有遇到任何问题。我只是想证明标签中的一些文本(以及其他一些属性)。

我尝试在标签本身,NSMutableAttributedString上设置文本对齐方式,还尝试在不同的地方(layoutSubviews等)进行所有操作,以查看它是否会改变任何东西,但没有运气。

我所拥有的非常简单:

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .justified

let finalString = "1 500 INMILES FOR FREE\nBY ADDING YOUR BOARDING PASS"
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: finalString)

attributedString.addAttribute(.paragraphStyle,value: paragraphStyle,range: NSMakeRange(0,attributedString.length))
attributedString.addAttribute(.font,value: UIFont(name: "Montserrat-Bold",size: 20.0)!,range: (finalString as Nsstring).range(of: "1 500"))
attributedString.addAttribute(.font,value: UIFont(name: "Montserrat-Light",size: 18.0)!,range: (finalString as Nsstring).range(of: "INMILES FOR FREE"))

self.myLabel.attributedText = attributedString

这是我得到的结果:

Correct

以及我的期望:

enter image description here

我已经尝试了很多我在SO上发现的所有东西,但到目前为止没有任何效果,我一定会丢失一些东西...

任何帮助将不胜感激!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。