title: Fail to automatically resize NSTextField under NSView (as menu item)
body: <p>I am an <strong>inexperienced</strong> user trying to learn via the simple projects creation process... I request your assistance as I have not found a working solution for two whole days now, digging the Xcode Help and Google.</p>
  
  <p>I have a simple MacOS X (10.6.x) application that creates (in-code) an extra NSMenuItem to the XIB status bar menu. On my AppDelegate, I create an object that loads the NSView (from MainMenu.xib):</p>
  
  <pre><code>// Add menu entry for NSView object
  NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:@"Placeholder"
                                          action:nil
                                          keyEquivalent:@""];
  [newItem setView:theView];
  [newItem setEnabled:NO];
  [newItem setTarget:self];
  [calendarMenu insertItem: newItem atIndex:0];
  [newItem release];
  </code></pre>
  
  <p>In my MainMenu.xib, besides the menu structure, I have another object set as NSView and under it, NSTextField (occupying all the space of the view). The menu seems to load the view window.</p>
  
  <p>Later on, I set some string to NSTextField but I cannot adjust the height accordingly; it's either too much or crops:</p>
  
  <pre><code>// Crop last newline character
  NSString *menuCelebrations = [NSString stringWithString:
          [celebName substringToIndex:([celebName length] - 1)]];
  NSFont *msgFont = [NSFont menuBarFontOfSize:12.0];
  
  // Set attributes
  [theTextField setFont:msgFont];
  [theTextField setStringValue:menuCelebrations];
  </code></pre>
  
  <p>The top menu now displays the longer text that I want, wrapped etc. but I cannot adjust the height properly with something like:</p>
  
  <pre><code>theView setFrame: NSMakeRect([theView frame].origin.x,
              [theView frame].origin.y,
              calendarMenu.size.width,
              newHeightFloat)];
  </code></pre>
  
  <p>As a newbie, I tried things like these for automatic resize, but to no avail obviously:</p>
  
  <pre><code>[theTextField sizeToFit];
  [theTextField autoresizesSubviews];
  [theView setAutoresizingMask:NSViewHeightSizable];
  [theView setNeedsDisplay:YES];
  </code></pre>
  
  <p>Needless say that I tried numerous attribute-combinations in Interface Builder (where the text field resizes with the view etc.). Nothing worked... I still cannot figure out a way to <strong>calculate and set the height</strong> to either NSView or NSTextFieled that is the sub-object.</p>
  
  <p>I found ideas and code over here at <a href="http://www.stackoverflow.com/">www.stackoverflow.com</a> and <a href="http://www.cocoabuilder.com/" rel="nofollow">www.cocoabuilder.com</a> but people mention the use of NSLayoutManager, NSTextStorage and NSTextContainer that Apple suggests somewhere in the documentation (look for chapter/reference "Calculating Text Height" that has some code, but fails to be implemented); others suggest that Apple's calculates the box but rendering that box does miss some pixels at the bottom.</p>
  
  <p>A <a href="http://www.cocoabuilder.com/archive/cocoa/153626-text-height-for-printing-fixed-width.html" rel="nofollow">reference</a> to Matt Neuburg's work (instead of NSLayout that Apple suggests) that makes proper calculation (with a sample project) seems to work well but on NSTextView objects...</p>
  
  <p>Must I create a separate/custom class for this NSView? Should I prefer NSTextView to NSTextField?</p>
  
  <p>Did anyone manage to adjust the height (only) to the proper size? I would surely appreciate some help with a code sample.</p>
  
  <p>Am I digging <strong>too deep without proper understanding</strong> of the methods in place?</p>