gpt4 book ai didi

ios - 在一个属性字符串中使用多种样式

转载 作者:可可西里 更新时间:2023-11-01 00:39:25 26 4
gpt4 key购买 nike

let myString = text1 + " (\(text2) people added)"
let myAttribute = [ NSAttributedStringKey.foregroundColor: UIColor.blue ]
let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
cell.textLabel?.attributedText = myAttrString

如何在一个属性字符串中使用不同样式的 text1"(\(text2) people added)"

最佳答案

是的,你可以

    var attributedText = NSMutableAttributedString()
let str1 = text1
let str2 = " (\(text2) people added)"
let attr1 = [NSAttributedStringKey.foregroundColor: UIColor.blue]
let attr2 = [NSAttributedStringKey.foregroundColor: UIColor.red]
attributedText.append(NSAttributedString(string: str1, attributes: attr1))
attributedText.append(NSAttributedString(string: str2, attributes: attr2))

cell.textLabel?.attributedText = attributedText

关于ios - 在一个属性字符串中使用多种样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48458028/

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