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 02-18-2010, 07:53 AM   #51 (permalink)
Omid
Registered Member
 
Join Date: Jan 2009
Posts: 4
Omid 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!
First of all thanks for the tutorial and the code above.
Can anyone tell me how to position a rotated text correctly?
I try this, but it's not correct:
Code:
UIGraphicsPushContext(pdfContext);
	
	CGContextTranslateCTM(pdfContext,txtPos.origin.x, newY);
	CGContextScaleCTM(pdfContext, 1.0, -1.0);
	
	CGAffineTransform textTransform = CGAffineTransformMakeRotation(/*M_PI*2 - */currentAngle);
	CGContextConcatCTM(pdfContext, textTransform);
	
	
	NSString *string =[NSString stringWithCString:text];
	[string drawInRect:CGRectMake(0, 0, txtPos.size.width, txtPos.size.height) withFont:[UIFont fontWithName:@"Helvetica" size:48]];
	
	UIGraphicsPopContext();
Thanks in advance,

Omid
Omid is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,486
Threads: 94,041
Posts: 402,630
Top Poster: BrianSlick (7,978)
Welcome to our newest member, hughricotta
Powered by vBadvanced CMPS v3.1.0

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