Re: Autoresizable NSTextField (2)
Re: Autoresizable NSTextField (2)
- Subject: Re: Autoresizable NSTextField (2)
- From: Lorenzo <email@hidden>
- Date: Sat, 30 Oct 2004 10:59:35 +0200
Hi,
I did what you say (I hope) but, the fieldEditor already adjusts its frame
size and bounds size automatically. I have seen this putting two NSLog here
below. Anyway, I tried to set the size by myself and redisplay it but the
problem is still there. I cannot see the new text.
NSText *fE = [[self window] fieldEditor:NO forObject:self];
if(fE != nil){
NSLog(@"fEd FrameSize %.2f, %.2f",
[fE frame].size.width, [fE frame].size.height);
NSLog(@"fEd BoundsSize %.2f, %.2f",
[fE bounds].size.width, [fE bounds].size.height);
[fE setFrameSize:NSMakeSize(strWidth, [fE frame].size.height)];
[fE setNeedsDisplay:YES];
}
The good thing I didn't mention earlier is that when I close the editing
with [[self window] endEditingFor:self]; I can see the text properly.
Best Regards
--
Lorenzo
email: email@hidden
>
From: Robbie Haertel <email@hidden>
>
Reply-To: Robbie Haertel <email@hidden>
>
Date: Fri, 29 Oct 2004 14:39:03 -0600
>
To: Lorenzo <email@hidden>
>
Subject: Re: Autoresizable NSTextField (2)
>
>
I'm no expert, but I do know that NSControl through NSCell adds the
>
window's default text editor as a subview (I can't remember what it is
>
a subview to). So in effect, you have an NSTextField on top of your
>
control. So, you have resized your control but not the text editor.
>
Grab the window's text editor in your textDidChange: method and resize
>
that as well. I haven't done this, but I know this is the problem. I
>
just hope the solution works.
>
>
Good luck!
>
Robbie
>
>
>
On Fri, 29 Oct 2004 22:21:07 +0200, Lorenzo <email@hidden> wrote:
>
> 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
>
>
_______________________________________________
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