• 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
I want NSTextField to grow as text is entered
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I want NSTextField to grow as text is entered


  • Subject: I want NSTextField to grow as text is entered
  • From: Ian Jackson <email@hidden>
  • Date: Mon, 9 May 2005 20:37:00 +1200

Hi,

I've been looking around for a solution to this problem, and there certainly seem to be people who can make this work, but after gathering together everything I understand about the text architecture, it just doesn't work. So with an NSView in a window, this was my attempt to make the simplest possible application to figure it out.

- (void)drawRect:(NSRect)rect
{


[self setAutoresizesSubviews:YES];


textStorage = [[NSTextStorage alloc] init];


NSLayoutManager *layoutManager;
layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];
[layoutManager release];

NSRect cFrame = [[[self window] contentView] frame];
NSTextContainer *container;
container = [[NSTextContainer alloc] initWithContainerSize:cFrame.size];
[container setWidthTracksTextView:NO];
[layoutManager addTextContainer:container];
[container release];




NSRect tvRect;
tvRect.origin.x = 150;
tvRect.origin.y = 150;
tvRect.size.width = 100;
tvRect.size.height = 100;


NSTextView *theTextView = [[NSTextView alloc] initWithFrame:tvRect textContainer:container];
[theTextView setPostsFrameChangedNotifications:YES];
[theTextView setHorizontallyResizable:YES];
[theTextView setAutoresizingMask:NSViewNotSizable];
[self addSubview:theTextView];
[theTextView release];
}

So this should be a fairly standard implementation of NSTextStorage, NSLayoutManager, etc. What I hope to happen is that as I type in the NSTextView the rect initially described by tvRect should grow and display text. But what actually happens is that the text continues on, but doesn't display till it gets to the edge of the container rect, when it starts on the next line of the NSTextView. I think there are only a few superfluous lines (e.g. setAutoresizesSubviews) but I really want to know what the key thing is that I'm missing. Thank you.
 _______________________________________________
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: I want NSTextField to grow as text is entered
      • From: Ryan Stevens <email@hidden>
  • Prev by Date: Re: context-sensitive menu for NSTextField
  • Next by Date: Problem converting pdfs to jpegs with Cocoa & Quartz...
  • Previous by thread: Re: context-sensitive menu for NSTextField
  • Next by thread: Re: I want NSTextField to grow as text is entered
  • Index(es):
    • Date
    • Thread