UILabel有两种不同颜色的文字 [英] UILabel with two different color text
问题描述
如何为字体提供两种不同颜色的 UILabel
?我将使用两个不同的字符串中的文本,并且我希望将第一个字符串的文本设为红色,其次为绿色。字符串的长度都是可变的。
How can i have a UILabel
with two different colors for the font? I will have text in two different strings and i want to make text with first string as red and second as green. The length of both the string is variable.
推荐答案
你不能在 UILabel
秒。但我的建议是,不要使用多个 UILabel
而只关注 NSAttributedString
。查找 UIControllers
绘制 NSAttributedString
,因为 UILabel
, UITextView
不支持 NSAttributedString
。
You can't do this within a UILabel
s. But my suggestion is that instead of using multiple UILabel
just concentrate on NSAttributedString
. Find UIControllers
that draw NSAttributedString
because UILabel
, UITextView
do not support NSAttributedString
.
PS:if您计划分发iOS6或更高版本的应用程序,因为UILabel现在支持NSAttributedString,您应该直接使用UILabel而不是OHAttributedLabel,因为它现在可以由操作系统本机支持。
这篇关于UILabel有两种不同颜色的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!