• 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: Force NSTextField (multiline wrapping label) to grow vertically?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Force NSTextField (multiline wrapping label) to grow vertically?


  • Subject: Re: Force NSTextField (multiline wrapping label) to grow vertically?
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 09 Apr 2015 13:28:33 -0500

On Apr 9, 2015, at 11:24 AM, Steve Mills <email@hidden> wrote:

> I can't figure out a combination of constraints and hugging/compression values that will cause an NSTextField used as a multiline wrapping label to grow vertically when the window is resized horizontally.

> I tried setting the label's vertical content hugging to 1 and the vertical content compression resistance to 1000, which seem like the right values to me. Does its intrinsic size never grow to fully contain the wrapped text?

Constraints never affect a view's intrinsic content size, at least not without some help from you.  The content hugging and compression resistance priorities take the intrinsic content size as input, more or less.  Or, thought of another way, they act based on the intrinsic content size.

As you've found, by default, a text field will compute an intrinsic content size as though it were laid out in one long line.

Since 10.8, though, NSTextField has had a preferredMaxLayoutWidth property.  If you set that to a non-zero value, it will compute its intrinsic content size based on the rect it would need if it were wrapped at that width.

That's still static, though.  By itself, it doesn't help as your window changes width.

In a parent view, you could override the -layout method with something like this to adjust it dynamically:

- (void) layout
{
    textField.preferredMaxLayoutWidth = 0;
    [super layout]
    textField.preferredMaxLayoutWidth = NSWidth([textField alignmentRectForFrame:textField.frame]);
    [super layout];
}

Regards,
Ken


_______________________________________________

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


  • Follow-Ups:
    • Re: Force NSTextField (multiline wrapping label) to grow vertically?
      • From: Steve Mills <email@hidden>
References: 
 >Force NSTextField (multiline wrapping label) to grow vertically? (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: objc_msgSend() selector name: tableView:objectValueForTableColumn:row:
  • Next by Date: Re: objc_msgSend() selector name: tableView:objectValueForTableColumn:row:
  • Previous by thread: Force NSTextField (multiline wrapping label) to grow vertically?
  • Next by thread: Re: Force NSTextField (multiline wrapping label) to grow vertically?
  • Index(es):
    • Date
    • Thread