iPhone iOS如何在UITextView中更改某些单词的颜色? [英] iPhone iOS how to change color of some words within UITextView?

查看:66
本文介绍了iPhone iOS如何在UITextView中更改某些单词的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序用户提供在UITextView中突出显示或更改所选单词的颜色的功能.我知道如何更改整个文本颜色:

I'd like to offer a user of my app the ability to highlight or change color of selected words within a UITextView. I know how to change the entire text color:

 textView.textColor = [UIColor redColor];

这不是我想要的.我需要知道如何更改UITextView中任意字符序列的颜色.我尚未在最新的文本视图中看到此功能,因此我认为不支持该功能.是否有关于如何在UITextView中更改颜色或突出显示文本块的开源项目或示例?

This is not what I'm looking for. I need to know how to change color of arbitrary sequences of characters within a UITextView. I have not seen such feature in the text views up to date, so I think it's not supported out of the box. Are there any open source projects or examples on how to change color or highlight blocks of text within a UITextView?

谢谢!

推荐答案

您可以创建CATextLayer并为其分配NSAttributed字符串.请在此处中查看.您可以使用 DTCoreText

You can create CATextLayer and assign NSAttributed string to it. Have a look at here. You can make use of DTCoreText

这篇关于iPhone iOS如何在UITextView中更改某些单词的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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