2

Possible Duplicate:
TTT attributed Label Multi- colored Font help

How can I do like this picture in iphone? Anyone help me. Should I use Core Animation or Text Core or something else? http://s7.postimage.org/qgbhw7c3v/Capture.png

Community
  • 1
  • 1
hackchick
  • 25
  • 3

2 Answers2

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);    

Note => Add CoreText framework in the project and import it.

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • @hackchick also see this tutorial for multiple color in string.. http://soulwithmobiletechnology.blogspot.in/2011/06/coretext-tutorial-for-ios-part-1.html – Paras Joshi Dec 06 '12 at 06:45
  • i want to change each pixcel of letter in sentence, for example, letter "A", I just only want to change red color for 1/2 part of letter "A", how can I do that? – hackchick Dec 06 '12 at 07:13
  • here if you want to multicolor every letter then you wan use this logic dude.. just set color with image using this [UIColor colorWithPatternImage:[UIImage imageNamed:@""]]; try it just implement it and change some code – Paras Joshi Dec 06 '12 at 07:23
  • also see the discussion from my this answer http://stackoverflow.com/questions/13579209/two-colors-for-uilabel-text/13579318#13579318 and use this answer and upvote the answer if u like it.. i hope you got it.. :) – Paras Joshi Dec 06 '12 at 07:24
  • yah, my idea is build an basic karaoke app. Lyric will show and color will change of each pixcel of letter, like this http://www.youtube.com/watch?v=MZxvu2sXzug, but I don't know I should use Core Animation, Core Text or Quazt 2D, it is very hard for me, i'm newbie in Xcode and I from Vietnam so translate document write by English maybe hard for me :( – hackchick Dec 06 '12 at 07:32
  • after some time you'll also master in xcode and iphone if you love to your this work dude.. :) – Paras Joshi Dec 06 '12 at 07:34
0

You can Use OHAtrributedLabel for this easy and effective : https://github.com/AliSoftware/OHAttributedLabel

spider1983
  • 1,098
  • 1
  • 7
  • 14
  • thanks for your anwser, but i want to change each pixcel of letter in sentence, for example, letter "A", I just only want to change red color for 1/2 part of letter "A", how can I do that? – hackchick Dec 06 '12 at 07:13