无法在UITextView中显示具有不同颜色的所选文本,该怎么办? [英] Can't display selected text with different colors in UITextView, what should I do?

查看:42
本文介绍了无法在UITextView中显示具有不同颜色的所选文本,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用不同的颜色在UITextView中显示文本,并在其中加下划线(以表明它们是错误的-通常在拼写检查程序中完成),但是当前版本的UIKit无法实现.我还应该追求什么其他选择?

I want to display texts in UITextView with different colors and underline some of them (to show they are erroneous - commonly done in spellchecker) but that's not possible with the current version of UIKit. What other options should I pursue?

我正在考虑将UIScrollView子类化(因为我要处理大量文本),并使用CoreGraphics将文本转换成UIView(作为内容),并在输入新文本时将新文本转换成UIView.那是个好方法吗?

I am thinking of subclassing UIScrollView (as I am dealing with a lot of texts) and blit the text into a UIView (as the content) using CoreGraphics, and as new text is entered, I will blit new text onto it. Is that a good approach?

推荐答案

推荐的方法是生成HTML并使用UIWebView.那是一个滚动视图,因此您应该拥有所需的所有功能.

The recommended approach is to generate HTML and use a UIWebView. That is a scroll view so you should have all the functionality you need.

如果您希望对文本进行更多控制,那么您的方法很好,尽管您可以使用UIKit NSString扩展来绘制文本.具体来说,您需要drawAtPoint:withFont:

If you want more control over the text then your approach is good although you can probably use the UIKit NSString extensions to draw your text. Specifically, you want drawAtPoint:withFont:

这篇关于无法在UITextView中显示具有不同颜色的所选文本,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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