title: UILabel with Paragraph Style Line Spacing
body: <p>I'm trying to create a messaging application and am encountering a very strange issue.</p>
  
  <p><a href="https://i.stack.imgur.com/FjAnu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FjAnu.png" alt="enter image description here"></a></p>
  
  <p>The reason there is so much space between "Thomas" and the bottom of the text bubble is becasue the <code>UILabel</code> is creating another line. Currently I'm setting the label's text using the <code>attributedText</code> property, and passing in a <code>NSMutableParagraphStyle</code> with a <code>line spacing</code> of <code>8</code>. If I set the <code>line spacing</code> to <code>0</code>, the space between "Thomas" and the bottom of the text bubble goes away like so:</p>
  
  <p><a href="https://i.stack.imgur.com/XW72C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XW72C.png" alt="enter image description here"></a></p>
  
  <p>Here's where it gets strange though. If I set the paragraph <code>line spacing</code> back to <code>8</code>, and add a couple more characters to the line, the text bubble appears without the extra line:</p>
  
  <p><a href="https://i.stack.imgur.com/EdBF5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EdBF5.png" alt="enter image description here"></a></p>
  
  <p>All help is greatly appreciated :)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class MessageTableViewCell: UITableViewCell {
      var didSetupConstraints = false
  
      var thumbnail = UIImageView.newAutoLayoutView()
      let messageTailIcon = UIImageView.newAutoLayoutView()
      var messageView = UIView.newAutoLayoutView()
      var messageLabel = UILabel.newAutoLayoutView()
  
      override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
          super.init(style: style, reuseIdentifier: reuseIdentifier)
          setupViews()
      }
  
      required init(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      func setupViews() {
          thumbnail.image = UIImage(named: "ThomasBaldwin")
          thumbnail.layer.cornerRadius = 17.5
          thumbnail.clipsToBounds = true
  
          messageTailIcon.image = UIImage(named: "MessageTailIcon")
  
          messageView.backgroundColor = Application.greyColor
          messageView.layer.cornerRadius = 10
  
          let paragraphStyle = NSMutableParagraphStyle.new()
          paragraphStyle.lineSpacing = 8
  
          messageLabel.numberOfLines = 0
          messageLabel.layer.cornerRadius = 10
          messageLabel.attributedText = NSMutableAttributedString(
              string: "Thomas says hello",
              attributes: [
                  NSFontAttributeName: UIFont(name: "AvenirNextLTPro-Regular", size: 12.5)!,
                  NSForegroundColorAttributeName: UIColor.colorFromCode(0x262626),
                  NSBackgroundColorAttributeName: Application.greyColor,
                  NSKernAttributeName: 0.5,
                  NSParagraphStyleAttributeName: paragraphStyle
              ]
          )
  
          contentView.addSubview(thumbnail)
          contentView.addSubview(messageView)
          messageView.addSubview(messageTailIcon)
          messageView.addSubview(messageLabel)
          updateConstraints()
      }
  
      override func updateConstraints() {
          if !didSetupConstraints {
  
              thumbnail.autoPinEdgeToSuperviewEdge(.Top, withInset: 15)
              thumbnail.autoPinEdgeToSuperviewEdge(.Leading, withInset: 8.5)
              thumbnail.autoSetDimensionsToSize(CGSize(width: 35, height: 35))
  
              messageView.autoPinEdgeToSuperviewEdge(.Top, withInset: 17.5)
              messageView.autoPinEdge(.Leading, toEdge: .Trailing, ofView: thumbnail, withOffset: 10)
              messageView.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 24.5)
              messageView.autoPinEdgeToSuperviewEdge(.Bottom)
  
              messageTailIcon.autoPinEdgeToSuperviewEdge(.Top, withInset: 15)
              messageTailIcon.autoPinEdgeToSuperviewEdge(.Leading, withInset: -10)
              messageTailIcon.autoSetDimensionsToSize(CGSize(width: 18, height: 9))
  
              messageLabel.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 8.5, left: 10, bottom: 8.5, right: 5), excludingEdge: .Trailing)
              messageLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 0, relation: .GreaterThanOrEqual)
  
              didSetupConstraints = true
          }
  
          super.updateConstraints()
      }
  
  }
  </code></pre>
  
  <p>If you would like to view a sample project demonstrating the issue, I've pushed one to <a href="https://github.com/thomasbaldwin/SampleMessage" rel="nofollow noreferrer">github</a></p>