• 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: Resizing custom subclassed NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resizing custom subclassed NSTextView


  • Subject: Re: Resizing custom subclassed NSTextView
  • From: Joe White <email@hidden>
  • Date: Thu, 09 Jun 2011 00:19:20 +0100

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 <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Resizing custom subclassed NSTextView
      • From: Ross Carter <email@hidden>
References: 
 >Resizing custom subclassed NSTextView (From: Joe White <email@hidden>)
 >Re: Resizing custom subclassed NSTextView (From: Ross Carter <email@hidden>)

  • Prev by Date: Re: Helper Tools and launchd. Was: Login item not hidden
  • Next by Date: Re: Helper Tools and launchd. Was: Login item not hidden
  • Previous by thread: Re: Resizing custom subclassed NSTextView
  • Next by thread: Re: Resizing custom subclassed NSTextView
  • Index(es):
    • Date
    • Thread