0

I have a code which worked just fine until I built my project with iOS 7.1. Before, the text correctly showed on PDF page.

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

But now, everything in formatting dictionary is being disregarded. The PDF document shows black text of default font and size.

Thank you for responses.

2 Answers2

0

I would try using an NSAttributedString and find whether this works. I do not have a good reason as to why your code has stopped working, but try this:

//    obviously these variables are examples, keep whatever variables you are using
UIFont *font = [UIFont fontWithName:@"whatever_font" size:16.0f];
NSParagraphStyle *paragraphStyle = [NSParagraphStyle defaultParagraphStyle];

NSDictionary *attributes = @{NSFontAttributeName : font, NSParagraphStyleAttributeName : paragraphStyle, NSForegroundColorAttributeName : [UIColor redColor]};

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:exampleString attributes:attributes];

[attributedString drawInRect];
Infinity James
  • 4,667
  • 5
  • 23
  • 36
0

You can try this:

UIGraphicsPushContext(ctx);

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

UIGraphicsPopContext();
Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
Kate
  • 1,107
  • 8
  • 7
  • It's been long, and looking at code, I don't see the difference, but pushing context was not part of solution. Anyway, thank you for your response. – Stanley Kubrick Jan 06 '15 at 10:05