• 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: Most efficient way of measuring text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Most efficient way of measuring text


  • Subject: Re: Most efficient way of measuring text
  • From: Graham Cox <email@hidden>
  • Date: Wed, 13 May 2009 11:31:50 +1000


On 13/05/2009, at 7:16 AM, Dave Keck wrote:

text rects. Has anyone come up with a very fast way to estimate the size of
some text, more importantly the vertical size given a width.

You didn't mention that you tried NSAttributedString (specifically, its -size method.) Does it suit your needs, or is it what you consider too slow?


The -size method assumes the text is laid out on one line, so the height it returns is the line height. Even then it's usually pretty inaccurate - I've found it typically underestimates the necessary space by about 25% in each dimension, though it depends on the exact fonts the string is using.

The methods in NSLayoutManager are the best way to accurately measure text, as the OP is already doing.

You might be able to speed things up by keeping the layout manager around so that the information it caches is not destroyed every time.

--Graham


_______________________________________________

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: 
 >Most efficient way of measuring text (From: Alejandro Rodriguez <email@hidden>)
 >Re: Most efficient way of measuring text (From: Dave Keck <email@hidden>)

  • Prev by Date: Re: Changing name of newly created NSDocument (instead of 'Untitled i')
  • Next by Date: Text encoding issues
  • Previous by thread: Re: Most efficient way of measuring text
  • Next by thread: [iPhone] Getting an UIImageView to display under a UITableView
  • Index(es):
    • Date
    • Thread