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

Re: NSTextField & sizeToFit


  • Subject: Re: NSTextField & sizeToFit
  • From: Russell Ahrens <email@hidden>
  • Date: Mon, 11 Jun 2001 00:20:24 -0400

Adding a [field setNeedsDisplay:YES] right after the [field sizeToFit] works, but not with the timing expected. When I put it in my controller's textDidChange method, the field resized down to one character until I started typing characters in another field, at which time the NSTextField sized to the appropriate dimensions. Changing the setNeedsDisplay to a pure [field display] has the same effect. That wasn't ideal.

Adding a handler for textDidEndEditing would probably mean that the NSTextField would resize when you are done editing, rather than when you change another field, but that still means that the field is the wrong size while you're typing characters, which, at the risk of repeating myself, would not be ideal.

It's ugly, but what I did to make it work is the following:

- (void)textDidChange:(NSNotification *)notification {
// temporary string to hold the current value of the NSTextField
// and to plop it back in to fool the ?event loop? ?the TextField?
// well, SOMETHING into thinking that the text should be resized now
NSString * temp;

// only size the field as wide as it needs to be, no more
[field sizeToFit];
// inform the display system that the field is ready for redisplay
[field setNeedsDisplay:YES];

// crazy hacktastic way to REALLY make the system redisplay
temp = [field stringValue];
[field setStringValue:temp];

}

There has GOT to be a better way. I haven't found it yet; I would think that just sizeToFit followed by setNeedsDisplay should be enough. Hopefully someone more experienced can correct me?

Russell Ahrens
Oink Industries


On Sunday, June 10, 2001, at 06:34 PM, Russell Ahrens wrote:

I haven't tried it, but the documentation for sizeToFit: in NSControl
says, "This method neither redisplays the receiver, nor marks it as
needing display. You must do this yourself with either display or
setNeedsDisplay."

Have you tried that?

Russell Ahrens
Oink Industries

On Saturday, June 9, 2001, at 11:52 PM, Andre Lipinski wrote:

Hello,

I am trying to have an NSTextField change size as the user changes its
contents, much like the finder. I've tried a bunch of things in
controlTextDidChange: like [field sizeToFit] and a bunch of methods
from NSCell. I cannot find a way to make it work. The best I can get is
nowhere good enough. After an hour+ of trying, I must move on.

Do you know how to do this? Please tell!

Thank you kindly for your time,
Andre
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >Re: NSTextField & sizeToFit (From: Russell Ahrens <email@hidden>)

  • Prev by Date: Re: proof of cocoa superiority?
  • Next by Date: Cocoa Calling Carbon Question
  • Previous by thread: Re: NSTextField & sizeToFit
  • Next by thread: Re: NSTextField & sizeToFit
  • Index(es):
    • Date
    • Thread