Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8134271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:57:16+00:00 2026-06-06T09:57:16+00:00

I am trying to implement an NSTextView which resizes to fit its content. I

  • 0

I am trying to implement an NSTextView which resizes to fit its content. I am trying to make it so it has a maximum amount of lines. Meaning, that when this limit is reached, it will not grow any further and the user will be able to scroll it.

There seem to be a lot of people wanting this but I have not found a complete implementation of this.

The idea is to take the content size of the NSTextView and resize it so that it matches. I just can’t figure out how to set the layout size of the NSTextView. It does not seem to be it’s frame which needs to be set and which one might expect.

Can anyone please tell me how to set the frame of the NSTextView?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:57:19+00:00Added an answer on June 6, 2026 at 9:57 am

    It turns out that it’s the height of the scroll view which should be changed. Changing the height of an NSTextView can be done by overwriting the -didChangeText method like below.

    - (void)didChangeText
    {
        NSScrollView *scrollView = (NSScrollView *) self.superview.superview;
        NSRect frame = scrollView.frame;
    
        // Calculate height
        NSUInteger numberOfLines = [self numberOfLines];
        NSUInteger height = frame.size.height;
        if (numberOfLines <= 13)
        {
            height = 22 + (numberOfLines - 1) * 14;
            if (height < 22)
                height = 22;
        }
    
        // Update height
        frame.size.height = height;
        self.superview.superview.frame = frame;
    }
    

    Play around with the constants to get the result you wish for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement a function in my linkedlist class that will return total amount
I'm trying implement A* Start path finding in my games(which are written with JavaScript,
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
Trying to implement some nested loops that are spitting out good old nested html
Trying to implement a function that will return a list of ints the represent
SetFocus I'm trying implement the above Se Focus code in a Class Library that
All I am currently trying implement something along the lines of dim l_stuff as
Trying to implement a shell, mainly piping. I've written this test case which I
Im trying to implement some code i found on a website which duplicates a
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.