Hi Ross, thanks for replying. I wish I didn't have to subclass NSTextView, but from my understanding it seems like I have to.
Basically, the interface is separate editable objects that are usually single symbols with a few arguments included. This means that the each object is always one line high and usually not that wide. I started off using NSTextField (which I could resize easily) but I want to add syntax highlighting and auto-completion. From what I read NSTextView is the way forward. Thanks for the code, it does indeed resize for me. However it doesn't shrink when I remove text. >From poring over the Apple docs again ( http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html) I managed to get my the NSTextView subclass to resize. However it doesn't redraw itself and looks weird until I change the size of the main canvas. Would you say I am taking the wrong approach? All I wish to do is to have multiple instances of an object each with its own resizable/auto completing text field as a subview. Thank you for the help, Joe On 8 June 2011 19:05, Ross Carter <rosscarter...@me.com> wrote: > > > You don't need to override -didChangeText. In fact you don't need to > subclass NSTextView. > > If you create a new project in Xcode, and add the following code to your > application delegate class, you will see a textView that expands > horizontally as you type. I think that is what you want. > > - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { > NSTextView *tv = [[NSTextView alloc] initWithFrame:NSMakeRect(100, > 100, 100, 25)]; > [tv setHorizontallyResizable:YES]; > [tv setVerticallyResizable:NO]; > [tv setMaxSize:NSMakeSize(500, 25)]; > > [[self.window contentView] addSubview:tv]; > [tv release]; > > NSTextContainer *tc = [tv textContainer]; > NSSize tcSize = [tc containerSize]; > tcSize.width = 1.0e6; > [tc setContainerSize:tcSize]; > [tc setWidthTracksTextView:NO]; > } > > I assume you have a plan in place to deal with situations where the > textView at maximum width cannot display all the characters entered (or > pasted) by the user. > > -- Joe White Production Department, RjDj Tel : +44 7515 731499 Reality Jockey Ltd. Floor B “The Mission” 55 Holywell Lane London EC2A 3PQ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com