Autoresizable NSTextField (2)
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