Possible Duplicate:
TTT attributed Label Multi- colored Font help


我如何在iPhone中喜欢这张照片?有人帮我我应该使用Core Animation还是Text Core或其他?
http://s7.postimage.org/qgbhw7c3v/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框架并导入它。

关于iphone - 在iOS中更改句子的部分文本的颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13738149/

10-12 17:49