NSMutableAttributedString始终附加黑色文本

问题描述

当我在textView字符串中附加属性文本时,认情况下始终会附加黑色文本。我不想在代码的每一行中添加更多行和if语句(即addattributes)。有没有一种方法而无需增加太多行?即使我在以前的文本上添加白色,或者即使从情节提要中将文本颜色更改为白色,它也始终会附加黑色文本。

代码示例如下:

                    let attributedString = NSMutableAttributedString(string: "x")
                    attributedString.addAttributes([NSAttributedString.Key.baselineOffset: 5],range: NSRange(location: 0,length: 1))
                    let combination = NSMutableAttributedString(attributedString: textView.attributedText)
                    combination.append(attributedString)
                    textView.attributedText = combination

注意:我尝试添加此行但没有更改的解决方案:

textView.typingAttributes[NSAttributedString.Key.foregroundColor] = UIColor.white

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)