How to change color of a word in UITextView?

此生再无相见时 提交于 2019-12-23 03:11:23

问题


Is it possible to change UITextView`s color in particular range or particular word? If a word appear more than once in a view then change the color of that word.


回答1:


You'll need to use NSAttributedString. I recommend checking out AliSoftware's OHAttributedLabel which extends UILabel and adds support for setting text via NSAttributedString among other helpers. I'm using it in a current project and it's pretty fantastic.




回答2:


I solve the problem. I created subclass of UILable and UITextView used core text (CATextLayer) as a layer on label/textview and NSAttributedString will store all the information about the font and color



来源:https://stackoverflow.com/questions/7447466/how-to-change-color-of-a-word-in-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!