Observe that -drawInRect:withFont:lineBreakMode:alignment:
does not take a CGContextRef
parameter—it draws to the "current" graphics context. You don't show us how you got the context that you're drawing to, but typically that NSString
method would be used in a -drawRect
method with a context obtained like:
CGContextRef context = UIGraphicsGetCurrentContext();
You can make your context the "current context" with UIGraphicsPushContext()
(but make sure you also call UIGraphicsPopContext()
):
- (void)drawInContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
CGContextSaveGState(context);
// draw things, everything displays correctly ...
CGSize expectedCreditSize = [[gpData.credits stringValue] sizeWithFont:[UIFont
systemFontOfSize:self.fontSize]];
rect = CGRectMake(self.bounds.origin.x, self.bounds.size.height/2,
expectedCreditSize.width, expectedCreditSize.height);
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
[self.creditString drawInRect:rect
withFont:[UIFont systemFontOfSize:self.fontSize]
lineBreakMode:NSLineBreakByWordWrapping
alignment:NSTextAlignmentRight];
CGContextRestoreGState(context);
UIGraphicsPopContext();
}