更改绘制的NSString的子字符串的背景颜色? [英] Change the background color of a substring of a drawn NSString?

查看:50
本文介绍了更改绘制的NSString的子字符串的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Atebits的ABTableViewCell子类来优化滚动,以便根据搜索返回的结果为相当大的潜在数据源.(不过,无论哪种方式,我都强烈建议为最简单的表视图使用子类,它们就像黄油一样滚动!)

I am using the ABTableViewCell subclass by Atebits to optimize scrolling for rather large potential data sources depending on what my search returns. (Either way though, I'd highly recommend the subclass for even the simplest tableviews, they scroll like butter!)

我在视图中绘制了一个NSString:

I have an NSString drawn in a view:

[nameLabel drawInRect:nameRect withFont:nameLabelFont lineBreakMode:UILineBreakModeWordWrap];

我认为突出显示搜索到的单词(即名称包含搜索文本")是一个很酷的功能.这就像更改nameLabel子字符串后面的背景颜色一样简单吗?

I thought it would be a cool feature that the searched word (which is "Name CONTAINS searchText") be highlighted. Is this as simple as changing the background color behind a substring of nameLabel?

NSAttributedString似乎是我要寻找的东西,但事实证明,iPhone不存在它.

NSAttributedString seems to be what I'm looking for, but turns out it doesn't exist for the iPhone.

通过进一步的阅读,似乎HTML和UIWebView是实现此目标的方法...但是这似乎非常昂贵.这真的是解决方案吗?

From further reading, it would seem that HTML and a UIWebView is the way to go for this... but that seems awfully expensive. Is this really the solution?

推荐答案

嘿,请查看TTStyledLabel-它可能会做您想要的事情.

Hey, check out TTStyledLabel - it might do what you want.

这篇关于更改绘制的NSString的子字符串的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆