UITextField中的彩色子字符串 [英] Colored substring in UITextField

查看:145
本文介绍了UITextField中的彩色子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在输入 UITextField 时,我想更改特定子字符串(关键字)的颜色。

I would like to change the color only of particular substrings (keywords) while the user is typing in a UITextField.

在文档中我看到了属性 textColor ,但它确实改变了整个文本字符串的颜色,只想突出一些关键字。

In the documentation I saw the property textColor but it does change the color of the entire text string, while I would like to highlight only some keywords.

有可能吗?

推荐答案

如果使用NSAttributedStrings和CATextLayers或Core Text从头开始创建自己的文本字段,这是可能的,但这是一个非常复杂和困难的问题。

It's possible if you create your own textfield from scratch using NSAttributedStrings and CATextLayers or Core Text, but this is an incredibly complex and difficult problem.

这篇关于UITextField中的彩色子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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