具有多种字体颜色的UILabel文本 [英] UILabel Text with Multiple Font Colors

查看:115
本文介绍了具有多种字体颜色的UILabel文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 UILabel textColor 属性为两个不同的 UIColors ?基本上我正在尝试将 UILabel 文本属性中的第一个字符设为 greenColor ,其余为 blackColor 。我想避免使用两个不同的 UILabels ,因为我可能想要更改绿色字符文本中的位置。

Is there a way to have the textColor property of a UILabel be two different UIColors? Basically I'm trying to make the first character in the UILabel text property to be greenColor and the rest be blackColor. I would like to avoid using two different UILabels because I may want to change the position in the text of the green character.

推荐答案

UILabel不支持此属性...

UILabel doesnot supprt this property...

使用应使用NSAttributedString ...并使用控制器绘制NSAttributesString。 ..

Use should use NSAttributedString... and use controllers for drawing NSAttributesString...

NSAttributedString的控制器

更新:

从iOS 6开始,您可以执行以下操作:

From iOS 6 you can do the following :

label.attributedText = attributedString;

这篇关于具有多种字体颜色的UILabel文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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