在iOS中更改颜色的句子部分文本

时间:2012-12-06 06:31:35

标签: iphone ios xcode

  

可能重复:
  TTT attributed Label Multi- colored Font help

我怎么能在iphone中拍这张照片?任何人帮助我。我应该使用核心动画或文本核心还是别的什么? http://s7.postimage.org/qgbhw7c3v/Capture.png

2 个答案:

答案 0 :(得分:0)

您可以使用OHAtrributedLabel轻松有效:  https://github.com/AliSoftware/OHAttributedLabel

答案 1 :(得分:0)

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