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 7889809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:11:35+00:00 2026-06-03T06:11:35+00:00

Auto layout in Lion should make it fairly simple to let a text field

  • 0

Auto layout in Lion should make it fairly simple to let a text field (and hence a label) grow with text it holds.

The text field is set to wrap in Interface Builder.

What is a simple and reliable way to do this?

  • 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-03T06:11:36+00:00Added an answer on June 3, 2026 at 6:11 am

    The method intrinsicContentSize in NSView returns what the view itself thinks of as its intrinsic content size.

    NSTextField calculates this without considering the wraps property of its cell, so it will report the dimensions of the text if laid out in on a single line.

    Hence, a custom subclass of NSTextField can override this method to return a better value, such as the one provided by the cell’s cellSizeForBounds: method:

    -(NSSize)intrinsicContentSize
    {
        if ( ![self.cell wraps] ) {
            return [super intrinsicContentSize];
        }
    
        NSRect frame = [self frame];
    
        CGFloat width = frame.size.width;
    
        // Make the frame very high, while keeping the width
        frame.size.height = CGFLOAT_MAX;
    
        // Calculate new height within the frame
        // with practically infinite height.
        CGFloat height = [self.cell cellSizeForBounds: frame].height;
    
        return NSMakeSize(width, height);
    }
    
    // you need to invalidate the layout on text change, else it wouldn't grow by changing the text
    - (void)textDidChange:(NSNotification *)notification
    {
        [super textDidChange:notification];
        [self invalidateIntrinsicContentSize];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a simple WPF application without any auto layout. The goal is
I am trying to use the new Auto Layout in Lion because it seems
I have a simple layout http://goo.gl/BgaiB that I want to make it work for
My page layout looks something like this : <style type=text/css> #content-wrap { margin: 0
I try using the auto re-size stated at Auto Scale TextView Text to Fit
I have a layout that uses an EditText to let users search a database
I have following HTML layout <html> <head> <title></title> <meta http-equiv=Content-Type content=text/html; charset=UTF-8> <style type=text/css>
Possible Duplicates: Simple 2 column div layout 2 column layout in CSS I want
I've got a basic layout where the body div is set to a specific
I have a fixed size layout, centered using margin: 0 auto . I wonder

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.