Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-23-2009, 11:28 PM   #27 (permalink)
decay
Registered Member
 
Join Date: May 2009
Posts: 10
decay is on a distinguished road
Default

Quote:
Originally Posted by danielb21 View Post
Spent more time today exploring the [NSString drawInRect:] method to see if I could get it to work, and I now have a working solution. The key is that you have to push the graphics context onto the stack. Below is how it works:

Code:
NSString *string = @"Text to print.";

UIGraphicsPushContext(context);
CGContextTranslateCTM(context, 0, 20);
CGContextScaleCTM(context, 1.0, -1.0);
[string drawInRect:CGRectMake(0, 0, 300, 200) withFont:[UIFont fontWithName:@"Verdana" size:9]];
UIGraphicsPopContext();
So, the above code block pushes the context onto the stack, reverses the coordinates so that the text is drawn correctly, and then uses the drawInRect: withFont: method to draw the text, and finally calls the UIGraphicsPopContext() method.

It's important to note that each time you call UIGraphicsPushContext(context); you must also call the pop context method, otherwise you'll be left with nothing.

Thanks to decay for pushing me to investigate this more and enjoy everyone!
Your welcome, Daniel. Actually, I only call UIGraphicsPushContext() at the very end of the document. In between, I also use [UIImage drawInRect:] to stick pictures in the document, as well as drawing a line graph. I am generating PDFs on the fly, sometimes in the 17-20 page range. My app that uses this will be submitted to Apple tomorrow actually.
decay is offline   Reply With Quote
 

» Advertisements
» Online Users: 516
19 members and 497 guests
bignoggins, buggen, ClerurcifeDer, Clouds, dana0550, Duncan C, gdogdev, iAppDeveloper, ipodphone, krisk, linkmx, LunarMoon, Objective Zero, QuantumDoja, sacha1996, sCarlRodriguezj, sirenum, Steven.C, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,639
Threads: 94,102
Posts: 402,827
Top Poster: BrianSlick (7,990)
Welcome to our newest member, sCarlRodriguezj
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:54 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.