views:

176

answers:

2

How do I work out how much large an area drawing an NSString will occupy, i.e. by using:

[string drawAtPoint:p withAttributes:nil];

I ideally need to work this out before its drawn so I can space out the "areas" in which the strings are drawn appropriately.

+3  A: 

You can use sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:. It's an addition to NSString provided by UIKit (look for "NSString UIKit Additions Reference" in the docs).

pgb
This stuff can be so hard to find in the documentation. This only works for iPhone not for desktop cocoa.
Jacob
I assumed you were looking for an iPhone solution since the question is tagged as cocoa-touch. I'll remove that tag.
pgb
Actually i tagged it with cocoa and cocoa-touch because I am writing an app for both cocoa and cocoa-touch. (:
Jacob
+3  A: 

You can use the -[NSString sizeWithAttributes:] message.

arul
Thanks, this is exactly what I was looking for.
Jacob