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

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

  • Follow-Ups:
    • Re: Autoresizable NSTextField (2)
      • From: Robbie Haertel <email@hidden>
  • Prev by Date: Unwanted Run Log Window
  • Next by Date: Re: Distributed objects: can't send simple C struct by value
  • Previous by thread: Autoresizable NSTextField (2)
  • Next by thread: Re: Autoresizable NSTextField (2)
  • Index(es):
    • Date
    • Thread