• 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: NSTextField vertical sizeToFit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField vertical sizeToFit


  • Subject: Re: NSTextField vertical sizeToFit
  • From: Rob Napier <email@hidden>
  • Date: Thu, 17 Apr 2008 14:18:07 -0400

On Apr 13, 2008, at 4:38 AM, Jeff wrote:
Any way to take an NSTextField containing some amount of text, and resize it
vertically so all the text fits within the frame? The sizeToFit message
seems to do this, except on the horizontal axis.
Thank you!

It's a little easier to do this with an NSTextView:

NSRect frame = NSMakeRect(0, 0, someWidth, MAXFLOAT);
NSTextView *tv = [[NSTextView alloc] initWithFrame:frame];
[[tv textStorage] setAttributedString:someAttributedString];
[tv setHorizontallyResizable:NO];
[tv sizeToFit];

You can do a similar process with an NSTextField, but you have to set the NSParagraphStyle to word wrap, and I find it easier to just configure an NSTextView. If you need an NSTextField, I can walk through that.

-Rob

--
Rob Napier -- Software and Security Consulting -- http://robnapier.net
_______________________________________________

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: 
 >NSTextField vertical sizeToFit (From: Jeff <email@hidden>)

  • Prev by Date: Re: Simulating menu bar blink in Cocoa
  • Next by Date: Re: Cannot Remove Observer Error
  • Previous by thread: Re: Why should we set ivars to nil in dealloc?
  • Next by thread: EXC_BAD_ACCESS when calling CGContextDrawLayerInRect
  • Index(es):
    • Date
    • Thread