1

i have this code to set a DB(sqlite)text into my view.i just draw the text in view using core text..

NSMutableString *combined = [NSMutableString string];

for(NSUInteger idx = 0; idx < [delegatee.allSelectedVerseEnglish count]; idx++) {
    [combined appendFormat:@"  %d %@", 
     idx + 1, 
     [delegatee.allSelectedVerseEnglish objectAtIndex:idx]];
}

self.multiPageView.text =combined;

delegatee.allSelectedVerseEnglish this is the array...and between each sentence of the text i put numbers like this 1 haii this is nipin 2 haii this is stack overflow 3 etc etc ..like that..i am able to change the text color of all the text includes the numbers ..but i need to put "red"color to numbers .how to change the color of the numbers in the above code.is that possible?. thanks in advance.

stackiphone
  • 1,245
  • 3
  • 19
  • 41

1 Answers1

0

You need to use an NSMutableAttributedString and set the NSForegroundColorAttributeName value using the setAttributes:range: method.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • haii thanks for the answer...can you plz explain ..i dint know how to do this? – stackiphone Apr 29 '12 at 14:30
  • @stackiphone It's quite involved, but the answer to this SO question might give you a head start: http://stackoverflow.com/questions/3786528/iphone-ipad-how-exactly-use-nsattributedstring – trojanfoe Apr 29 '12 at 14:35
  • I see; you need to format the integer into a `NSString` using `[NSString stringWithFormat:@"%d", intValue]` put that into an `NSAttributedString` and append it to the larger `NSMutableAttributedString` you are building. As I said... quite involved. – trojanfoe Apr 29 '12 at 14:44
  • i put this code,,but i got a warning that NSMutableattributestring may not response to settextcolor ... NSAttributedString *str= [NSString stringWithFormat:@"%d", idx]; [str setTextColor:[UIColor redColor]]; – stackiphone Apr 29 '12 at 14:49
  • @stackiphone Follow the link to the example; you don't use `SetFontColor` you create an `NSDictionary` of attribute/value pairs that define colours, fonts and other stuff. – trojanfoe Apr 29 '12 at 14:53