如何更改文本字段文本的首字母的颜色 [英] How to change the color of first letter of a textfields text

查看:50
本文介绍了如何更改文本字段文本的首字母的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,文本框的文本的起始字母始终是一个美元符号.现在我需要更改美元符号的颜色,以便美元符号和其余文本应使用不同的颜色.我怎样才能做到这一点??任何想法

I have a textfield and starting letter of textfield's text is always a dollar sign.Now i need to change the color of dollar symbol so that dollar symbol and remaining text should be in different color. How can i do this?? Any idea

推荐答案

无法完成.UITextField中仅允许使用一种样式.

Can't be done standard. Only one style is allowed in a UITextField.

最好的主意:摆脱UITextField中的$,将其替换为空格,然后将UILabel放在顶部.

Best idea: get rid of the $ in the UITextField, replace it with whitespace, then place a UILabel on top.

第二个最好的主意:子类UITextField.

2nd best idea: subclass UITextField.

UITextField 有一个 drawTextInRect:方法,可能是您需要重写的所有方法.已记录

UITextField has a drawTextInRect: method which is probably all you need to override. Documented here. If you need more help, try googling or searching SO for how to subclass different UI classes, and get a feel for how to override draw methods (e.g. drawRect: for UIView)

这篇关于如何更改文本字段文本的首字母的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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