title: Clarifying the behaviour of NSLayoutManager & NSTextContainer with respect to vertical layout?
body: <h1>Code Sample</h1>
  
  <p>I have a <code>NSLayoutManager, NSTextContainer &amp; NSTextStorage</code> as properties in a custom <code>NSView</code> (not a TextView) initialized in <code>awakeFromNib()</code> as follows:</p>
  
  <pre><code>    textStorage = NSTextStorage(attributedString: self.attributedString)
  
      layoutManager = NSLayoutManager()
      textContainer = NSTextContainer(containerSize: NSMakeSize(self.frame.size.width, 1))
  
      layoutManager.addTextContainer(textContainer)
      textStorage.addLayoutManager(layoutManager)
      layoutManager.glyphRangeForTextContainer(textContainer)
  </code></pre>
  
  <p>The vertical <code>containerSize</code> of the <code>NSTextContainer</code> is deliberately set to 1 to see if it has the expected effect of hiding the text being rendered - it does not! It is making <strong>NO</strong> difference in the rendering of this text in the view - which is the subject of the question!</p>
  
  <p>In <code>drawRect</code> I include the lines below to draw the text:</p>
  
  <pre><code>let glyphRange = layoutManager.glyphRangeForTextContainer(textContainer)
  self.lockFocus()
  layoutManager.drawGlyphsForGlyphRange(glyphRange, atPoint: NSMakePoint(0, 0))
  self.unlockFocus()
  </code></pre>
  
  <h1>Findings</h1>
  
  <ol>
  <li>It appears best to work with your custom view in a flipped co-ordinate system like the <code>NSTextView</code> else I feel like I'm going to be in for a world of pain! Irrespective of this, NSLayoutManager always starts drawing its text internally in a flipped co-ordinate system (just like <code>NSTextView</code>)</li>
  <li>The <code>containerSize.width</code> property of <code>NSTextContainer</code> has the following effect: it is binding on a line level for all levels including the first (I know it's obvious but stick with me...)</li>
  <li>The <code>containerSize.height</code> property of <code>NSTextContainer</code> has a curve-ball: it will NOT be binding on the first line <strong>even if</strong> the containing view does not have the room to display it vertically BUT will be binding on subsequent lines</li>
  </ol>
  
  <p>*it took me a long time to come to this hypothesis about <code>containerSize.height</code> because I was only drawing one line! *</p>
  
  <h1>Question</h1>
  
  <ol>
  <li>Are my conclusions regarding <code>NSTextContainer</code> correct?</li>
  <li>What is the best way to control text drawing from a vertical perspective? I am wanting to place my single line of the text at the bottom of the view (and not have it floating at the top as in the default)</li>
  </ol>