I need to check an NSMutableString against values I've inserted when it originally was an NSString.
An example of it is:
NString* textToDraw = @"";
textToDraw = [textToDraw stringByAppendingString:[[NSString alloc] initWithFormat:@"
Summary of currently worked on process\n\nTitle name:\nResults for Process\n %@\n%@\n%@\n, resultOne, resultTwo, resultThree]];
resultOne
, resultTwo
, resultThree
are just standard NSString values
I then initialise a NSMutableAttributedString for some added formatting.
NSMutableAttributedString *summaryBody = [[NSMutableAttributedString alloc] initWithString:textToDraw];
CTFontRef centuryGothicStandard;
CTFontRef centuryGothicTitle;
centuryGothicStandard = CTFontCreateWithName(CFSTR("Century Gothic"), 12.0, nil);
centuryGothicTitle = CTFontCreateWithName(CFSTR("Century Gothic-Bold"), 24.0, nil);
//Modify the summary, so that the title is larger, and bolded, the subtitles are bolded, and the text is century gothic font
[summaryBody addAttribute:(id)kCTFontAttributeName
value:(__bridge id)centuryGothicStandard
range:NSMakeRange(0, [summaryBody length])];
What I need to do is modify resultOne
, resultTwo
and resultThree
to be red, I tried the answered solution in Change attributes of substrings in a NSAttributedString but I do not understand the concept.
Can I simply loop through the NSMutableAttributedString and find a specific character I insert say '|' for a beginning point and '?' for an end point? I've searched for getting a specific index, but nothing related to NSAttributedMutatableString pops up just NSRange, which I won't know specifically.
Here is some pseudo code to help explain what I think could be a possible solution:
textToDraw = [textToDraw stringByAppendingString:[[NSString alloc] initWithFormat:@" Summary of currently worked on process\n\nTitle name:\nResults for Process\n |%@?\n|%@?\n|%@?\n, resultOne, resultTwo, resultThree]];
(for int i = 0; i < [NSAttributedMutatableString length]; i++)
{
if(char at i == '|')
{
get an NSRange from this value to the char at i == '?'
[NSAttributedMutatableStringS addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor redColor].CGColor
range:NSMakeRange(0, NSRangeAbove])];
}
}
I currently can get the values of resultOne
and such and create NSAttributedStrings with the added attribute of changing the colour, the only problem is of course not knowing the index value, so that is another possibility.