title: Why when using TextKit to render text does the second line end up shorter than the first?
body: <p><strong>Sample project</strong>: <a href="http://d.pr/f/1coXu" rel="nofollow noreferrer">http://d.pr/f/1coXu</a></p>
  
  <p>I'm using TextKit to render some text into what is essentially a very basic recreation of <code>UILabel</code>. The code is very simple and in this example just draws a hardcoded <code>NSAttributedString</code> into the view itself:</p>
  
  <pre><code>class TextKitView: UIView {
      // TextKit Objects
      var textStorage: NSTextStorage!
      var textContainer: NSTextContainer!
      var layoutManager: NSLayoutManager!
  
      override init(frame: CGRect) {
          super.init(frame: frame)
  
          backgroundColor = UIColor.clearColor()
  
          layoutManager = NSLayoutManager()
  
          textStorage = NSTextStorage(attributedString: createAttributedString())
          textStorage.addLayoutManager(layoutManager)
  
          textContainer = NSTextContainer(size: CGSize(width: bounds.width, height: bounds.height))
          layoutManager.addTextContainer(textContainer)
      }
  
      required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
  
      override func drawRect(rect: CGRect) {
          let glyphRange = layoutManager.glyphRangeForTextContainer(textContainer)
          layoutManager.drawBackgroundForGlyphRange(glyphRange, atPoint: bounds.origin)
          layoutManager.drawGlyphsForGlyphRange(glyphRange, atPoint: bounds.origin)
      }
  
      private func createAttributedString() -&gt; NSAttributedString {
          let attributedString = NSMutableAttributedString(string: "Test string for testing", attributes: [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont.systemFontOfSize(16.0)])
  
          let labelAttributedString = NSAttributedString(string: "Foo bar\n testing", attributes: [NSForegroundColorAttributeName: UIColor.darkGrayColor(), NSBackgroundColorAttributeName: UIColor(white: 0.95, alpha: 1.0)])
          attributedString.appendAttributedString(labelAttributedString)
  
          return attributedString
      }
  }
  </code></pre>
  
  <p>However, when I create the view:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      let textKitView = TextKitView(frame: CGRect(x: 0.0, y: 100.0, width: 320.0, height: 320.0))
      view.addSubview(textKitView)
  }
  </code></pre>
  
  <p>It ends up looking like this:</p>
  
  <p><a href="https://i.stack.imgur.com/gmJx0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gmJx0.png" alt="enter image description here"></a></p>
  
  <p>Where you can see for some inexplicable reason the second line's background color and height is significantly shorter than the first, which looks really weird.</p>
  
  <p>How do I prevent this? What's causing this? If I use <code>UILabel</code> and provide the same attributed string both lines are the same height. I've attached a very minimal sample project above if it helps.</p>