• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: String attributes in the iPhone SDK
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String attributes in the iPhone SDK


  • Subject: Re: String attributes in the iPhone SDK
  • From: Greg Parker <email@hidden>
  • Date: Thu, 10 Dec 2009 15:49:38 -0800

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     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >String attributes in the iPhone SDK (From: Charlie Dickman <email@hidden>)

  • Prev by Date: String attributes in the iPhone SDK
  • Next by Date: Sending action from Switch type NSButton?
  • Previous by thread: String attributes in the iPhone SDK
  • Next by thread: Sending action from Switch type NSButton?
  • Index(es):
    • Date
    • Thread