简体   繁体   English

更改NSAttributedString上的背景颜色

[英]Changing Background color on NSAttributedString

I just wanted to know how could i change the background color of an NSAttributedString, i can see the background being white all the time, but i want to make it black. 我只是想知道如何更改NSAttributedString的背景颜色,我可以看到背景一直是白色,但我想让它变黑。

Is that possible?? 那可能吗?? Many thanks! 非常感谢!

I think you want NSBackgroundColorAttributeName. 我想你想要NSBackgroundColorAttributeName。 Such as: 如:

[mutableAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:selectedRange];

For swift 3.x attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(0, tillLocation)) 对于swift 3.x attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(0, tillLocation))

Helpfull link - Different way to attribute a string 有用的链接 - 属性字符串的不同方式

最好的计划是在具有黑色背景的视图上绘制字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM