开发者

Changing Background color on NSAttributedString

开发者 https://www.devze.com 2023-02-19 19:17 出处:网络
I just wanted to know how could i change the background color of an NSAttributedString, i can see the background being white all开发者_StackOverflow社区 the time, but i want to make it black.

I just wanted to know how could i change the background color of an NSAttributedString, i can see the background being white all开发者_StackOverflow社区 the time, but i want to make it black.

Is that possible?? Many thanks!


I think you want NSBackgroundColorAttributeName. Such as:

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


For Swift:

attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(0, tillLocation))

Helpful link - Different way to attribute a string


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

0

精彩评论

暂无评论...
验证码 换一张
取 消