• 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: NSLayoutManager for NSTextField (was Re: Metrics for a NSTextField)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLayoutManager for NSTextField (was Re: Metrics for a NSTextField)


  • Subject: Re: NSLayoutManager for NSTextField (was Re: Metrics for a NSTextField)
  • From: Eric Gorr <email@hidden>
  • Date: Thu, 26 Feb 2009 14:09:32 -0500


On Feb 26, 2009, at 12:21 PM, Eric Gorr wrote:

Hello Michael,

On Feb 26, 2009, at 11:10 AM, Michael Ash wrote:

On Thu, Feb 26, 2009 at 10:49 AM, Eric Gorr <email@hidden> wrote:
Unfortunately, sizeToFit does not work.

It doesn't appear one can constrain the width of a NSTextField and only have
it's height adjustable. Basically, sizeToFit provides a size that causes the
text in the field to fit on a single line.

Try sending -cellSizeForBounds: to your NSTextFieldCell. Give it a bounds with the correct width but a very tall height, and it should keep that width (or reduce it) and give you the appropriate height with wrapping.

Thanks. I believe that will provide me some of the metric information that I need, but not all of it.


For example, I also need to determine how many pixels 5 lines of text are with a constrained width and there will be other metric information for a NSTextField that I need as well.

What is clear is that a NSLayoutManager can answer every metric question I have and NSLayoutManager seems to be the place where all of the metric related methods have been placed.

What isn't clear how I can get a NSLayoutManager that will layout the text in the same way as a NSTextField, but perhaps this isn't possible because NSTextField does custom layout apart from a NSLayoutManager.

I thought I might be able to use a field editor, but as:

 http://ericgorr.net/cocoadev/label/TextFieldMetric.zip

demonstrates, getting a field editor for a NSTextField isn't so easy to obtain - of course, I may be doing some obviously (to someone else) wrong.

I can't believe the questions I want to ask of the text system are this difficult to obtain the answers to...

I have filed a bug report related to this:

rdar://6626911

which asks for the addition of a method (layoutManager) to NSTextField which would return an instance of NSLayoutManager which matches how a particular NSTextField lays out its text.
_______________________________________________


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: 
 >NSLayoutManager for NSTextField (was Re: Metrics for a NSTextField) (From: Eric Gorr <email@hidden>)

  • Prev by Date: NSTextView very slow, any remedies?
  • Next by Date: Re: How to center a custom NSView in a NSScrollView
  • Previous by thread: NSLayoutManager for NSTextField (was Re: Metrics for a NSTextField)
  • Next by thread: Compile errors
  • Index(es):
    • Date
    • Thread