попробуйте этот код, чтобы добавить строку в атрибутивную строку, я надеюсь, что это поможет вам.
func getStr(_ newstr:String, attrib:[NSAttributedString.Key: Any]) {
let newText = NSMutableAttributedString(string: newstr, attributes: attrib)
self.append(newText)
print(self)
}
вы должны передать newstr и attrib, как показано ниже.
let newstr: newstr = "your text here"
let attrib: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.black, .font: UIFont.systemFont(ofSize: 15)]