• 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: How do I compute the screen width of a particular font?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I compute the screen width of a particular font?


  • Subject: Re: How do I compute the screen width of a particular font?
  • From: "I. Savant" <email@hidden>
  • Date: Wed, 5 Aug 2009 15:56:33 -0400

On Aug 5, 2009, at 3:46 PM, Frederick C. Lee wrote:

Greetings: I need to adjust a UILabel's width per with of its text.
What I did was to get the text's length via [NSString length]. Of course,
the displayed UILabel width is too narrow to fully display the actual
string.
So I believe I need to compute the true width based on the number of
font-sized characters.

The "width of a font" doesn't really make sense. It might make sense to look for the width of the widest glyph in a font, but unless it's a fixed-width font, that metric is not the same as "the width of the attributed string, as rendered with the given attributes, including font, paragraph settings, etc." I'd recommend reading all font-related documentation.



Is there a simple, quick way to do this?


A quick look at the UILabel class reference shows that's a subclass of UIView. UIView has -sizeToFit, which, "Resizes and moves the receiver view so it just encloses its subviews." In the case of a UILabel, I would expect this (as on the Mac platform) to size to fit its attributed string keeping all its attributes in mind.

Disclaimer: I'm not an iPhone developer, but I am a Mac desktop developer. Much of Cocoa works the same across both platforms. The UI- related stuff differs in some key areas, but apparently not this one.

--
I.S.


_______________________________________________

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: 
 >How do I compute the screen width of a particular font? (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: How do I compute the screen width of a particular font?
  • Next by Date: Re: How do I compute the screen width of a particular font?
  • Previous by thread: How do I compute the screen width of a particular font?
  • Next by thread: Re: How do I compute the screen width of a particular font?
  • Index(es):
    • Date
    • Thread