Changing Background color on NSAttributedString

不羁的心 提交于 2019-11-28 07:29:55

问题


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.

Is that possible?? Many thanks!


回答1:


I think you want NSBackgroundColorAttributeName. Such as:

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



回答2:


The best plan would really be to draw the string on a view with a black background.




回答3:


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

Helpfull link - Different way to attribute a string



来源:https://stackoverflow.com/questions/5424003/changing-background-color-on-nsattributedstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!