Reputation: 755
I have an iOS app that draws shapes on the screen using a UIImage subclassed view and UIBezierPath to draw the lines of the shape.
Here is the code to draw the text:
// This is inside a loop
const unsigned int row = i;
const unsigned int column = j;
NSString* rowColumnId = [[NSString alloc] initWithFormat:@"%d, %d", column, row ];
CGPoint textCoord = shapeCoord[0];
textCoord.x += 5;
textCoord.y += 5;
[rowColumnId drawAtPoint:textCoord withFont:[UIFont fontWithName:@"Helvetica" size:9.0]];
On the screen, everything looks fine; both the shapes and the text are visible in both the iOS simulator and my iOS device
I needed to save the view as a PNG image, so I used the following code to do so:
// set up the rendering context
CGSize boardViewSize = [self bounds].size;
UIGraphicsBeginImageContext(boardViewSize);
[[self layer] renderInContext:UIGraphicsGetCurrentContext()];
// draw the view
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// convert to PNG
NSData* pngData = UIImagePNGRepresentation(viewImage);
UIImage* pngImage = [UIImage imageWithData:pngData];
return pngImage;
When I save the PNG, all I see are the shapes.
What code is needed in order to save the NSString drawn text as well?
Upvotes: 3
Views: 236
Reputation: 755
Well, I figured out the problem was that black text does not appear on a transparent PNG, though it is there.
So, the above listed question can be disregarded.
Upvotes: 1