• 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
Autoresizable NSTextField (2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Autoresizable NSTextField (2)


  • Subject: Autoresizable NSTextField (2)
  • From: Lorenzo <email@hidden>
  • Date: Fri, 29 Oct 2004 22:21:07 +0200

Hi,
I asked already but it seems nobody knows how to fix this problem...
I am trying to make an autoresizable NSTextField. So any time I type a
character it sets its width to accomplish the width of the string.
In order to do that I check for the width of the string at any new character
typed, using the method "textDidChange", so I update the NSTextField width.

The NSTextFiels updates its width properly, but I suppose its NSCell
doesn't, because the new NSTextField's area added looks like empty (no
visible text). How to fix this? Here's my code.

- (void)textDidChange:(NSNotification *)aNotification
{
NSAttributedString *aString = [[self cell] attributedStringValue];
NSDictionary *attrDict;
float strWidth;

attrDict = [aString attributesAtIndex:0 effectiveRange:nil];
strWidth = [[aString string] sizeWithAttributes:attrDict].width + 4;

[self setFrameSize:NSMakeSize(strWidth, [self frame].size.height)];

[self setNeedsDisplay:YES];
[[self superview] setNeedsDisplay:YES];
}


Best Regards
--
Lorenzo
email: email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: need to disable a custom NSToolbarItem which has a NSPopupButton
  • Next by Date: Re: Thread Cancelation
  • Previous by thread: need to disable a custom NSToolbarItem which has a NSPopupButton
  • Next by thread: Re: Autoresizable NSTextField (2)
  • Index(es):
    • Date
    • Thread