2012-11-29 126 views
0

我有這樣的代碼TTTAttributedLabel多種顏色

[label setText:@"ddddasdasdas" afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { 
      [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor blackColor] range:NSMakeRange(0,1)]; 
      [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor redColor] range:NSMakeRange(2,3)]; 
      [mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[UIColor greenColor] range:NSMakeRange(5,2)]; 
      return mutableAttributedString;}]; 

而且只有第一個字符改變顏色,但文本的其他部分並沒有改變。有任何想法嗎?

回答

-1

的問題是,我需要把.CGRef每種顏色,是我不好

0

嘗試:

[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)]; 

或:

[mutableAttributedString addAttribute:(NSString*)NSForegroundColorAttributeName value:(id)[[UIColor blackColor] CGColor] range:NSMakeRange(0,1)];