On Dec 10, 2009, at 3:44 PM, Charlie Dickman wrote:
> I use the following code to determine the height and width of a string in the 
> Snow Leopard version of an app
> 
>       NSMutableDictionary *textAttributes = [[[NSMutableDictionary alloc] 
> init] autorelease];
>       [textAttributes setObject: [NSFont fontWithName: @"Garamond Bold" size: 
> 24]
>                                                                 forKey: 
> NSFontAttributeName];
>       [textAttributes setObject: [NSColor blackColor]
>                                                                 forKey: 
> NSForegroundColorAttributeName];
> 
>               
>               NSString *text = [NSString stringWithFormat: @"%d", h];
>               NSSize textSize = [faceText sizeWithAttributes: 
> faceTextAttributes];
>                               
>               x -= faceTextSize.width / 2.;
>               y -= faceTextSize.height / 2.;
> 
> I'm tearing my hair out trying to figure out how to accomplish the same thing 
> in the iPhone SDK. Can anybody help me?

First, get a UIFont representing the font you want.
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIFont_Class/Reference/Reference.html

Then measure the string with -[NSString sizeWithFont:] or some variant thereof.
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSString_UIKit_Additions/Reference/Reference.html


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to