NT_iOS笔记—CoreText添加文字背景色(搜索的高亮显示)

转载请标明出处:http://blog.csdn.net/nt_tian/article/details/42458647

在CoreText里进行全文搜索,搜索的结果需要高亮显示,这个已经是很普遍的做法了。

在搜索结果列表中可以通过UILabel直接显示

[attributedString addAttribute: NSBackgroundColorAttributeName value:[UIColor orangeColor] range:range];
_conLabel.attributedText=attributedString;
但是当我开始进行CoreText文字高亮显示的时候发现了一个问题,CoreText对 NSMutableAttributedString 中的 NSBackgroundColorAttributeName属性不支持。
网上查了一下,CoreText的文字背景色需要自己手动的画上去。

好吧,那就只能自己画了,上代码:


你可能感兴趣的:(coretext,coretext文字背景色,ios)