Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使用某种通用方法更改uilabel字符串部分的颜色?_Iphone_Ios_Objective C_Uilabel_Nsattributedstring - Fatal编程技术网

Iphone 如何使用某种通用方法更改uilabel字符串部分的颜色?

Iphone 如何使用某种通用方法更改uilabel字符串部分的颜色?,iphone,ios,objective-c,uilabel,nsattributedstring,Iphone,Ios,Objective C,Uilabel,Nsattributedstring,有人能告诉我如何用一些通用方法改变uilabel字符串部分的颜色吗 让我解释一下 我有类似的标签 "10/05/2008 4 years", "10/05/2011 2 years", "20/06/1933 - 07/07/1970 37 years", "10/05/1982 30 years", "10/05/2008 4 years", "10/05/2011 2 years", "20/06/1933 - 07/07/1970 37 years" 现在我想

有人能告诉我如何用一些通用方法改变uilabel字符串部分的颜色吗

让我解释一下

我有类似的标签

  "10/05/2008 4 years",
  "10/05/2011 2 years",
  "20/06/1933 - 07/07/1970 37 years",
  "10/05/1982 30 years",
  "10/05/2008 4 years",
  "10/05/2011 2 years",
  "20/06/1933 - 07/07/1970 37 years"
现在我想做的是用不同的颜色来表示年份及其值,例如(4年)和用difrent字体表示不同颜色的日期

NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:peopleDate.text];
    [string addAttribute:NSForegroundColorAttributeName value:GraycolorForText range:NSMakeRange(10, 5)];
    [peopleDate setAttributedText:string];
这只会改变特定范围内的颜色,它不是通用的。因此,任何人可以给我任何解决方案吗???

可能重复的