gpt4 book ai didi

ios - NSMutableAttributedString 添加多个隐藏文本的属性

转载 作者:行者123 更新时间:2023-11-29 05:14:15 28 4
gpt4 key购买 nike

let text = "By accepting  you agree to our Terms of Service and Privacy Policy."
let attr = NSMutableAttributedString(string: text)

attr.setAttributes([.underlineStyle: 1, .foregroundColor: #colorLiteral(red: 0.7294117647, green: 0.6235294118, blue: 0.2823529412, alpha: 1).cgColor ],
range: (text as NSString).range(of: "Terms of Service"))

attr.setAttributes([.underlineStyle: 1, .foregroundColor: #colorLiteral(red: 0.7294117647, green: 0.6235294118, blue: 0.2823529412, alpha: 1).cgColor ],
range: (text as NSString).range(of: "Privacy Policy."))

This is the showing in terminal

-[__NSCFType set]: unrecognized selector sent to instance 0x6000039b2ca0

添加单个属性时工作正常

iOS Simulator 13.2.2Xcode 11.2.1Swift 5 上运行代码

最佳答案

这里是您需要将 cgColor 转换为 UIColor 才能使用 foregroundColor 属性

attr.setAttributes([.underlineStyle: 1, .foregroundColor: UIColor(red: 1, green: 0.556, blue: 0.232, alpha: 1)],
range: (text as NSString).range(of: "Terms of Service"))



attr.setAttributes([.underlineStyle: 1, .foregroundColor: UIColor(red: 1, green: 0.556, blue: 0.232, alpha: 1) ],
range: (text as NSString).range(of: "Privacy Policy."))

关于ios - NSMutableAttributedString 添加多个隐藏文本的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59347766/

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