我在字符串中使用以下占位符:%@
例如,我的字符串是String(format: “ greetings%@”,str)
如何为该动态占位符提供特定的颜色?
str
:let attributes: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.green]
let name = NSAttributedString(string: str, attributes: attributes)
let greeting = NSMutableAttributedString(string: "greetings ")
string.append(name)
label.attributedText = string