2

可能重复:
TTT 属性标签多色字体帮助

我怎样才能在iphone中像这张照片一样?任何人都可以帮助我。我应该使用 Core Animation 或 Text Core 还是其他东西? http://s7.postimage.org/qgbhw7c3v/Capture.png

4

2 回答 2

1
    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 框架并导入。

于 2012-12-06T06:42:42.447 回答
0

您可以使用 OHAtrributedLabel 来简单有效地完成此操作: https ://github.com/AliSoftware/OHAttributedLabel

于 2012-12-06T06:36:08.660 回答