title: NSAttributedString with baselineOffset can cause the last line to be cut off
body: <p>I’ve got an attributed string with a set baseline offset which renders as I’d expect.</p>
  <p><a href="https://i.stack.imgur.com/rsUWR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rsUWR.png" alt="enter image description here" /></a></p>
  <p>The issue is when I add any other style (color, strikethrough, link, etc) to only part of the string, the text gets positioned wrong so that the last line isn’t rendered.</p>
  <p><a href="https://i.stack.imgur.com/qzhH4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qzhH4.png" alt="enter image description here" /></a></p>
  <p>Is there a way to make this work properly?</p>
  <p>My original goal was to change the line height to be smaller than the default of the font, then move the baseline so the tops of some characters wont be cut off (like $).</p>
  <hr />
  <p>Here's the simplest version I could make to reproduce this in a playground.</p>
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  ​
  let baselineOffset: Float = 5
  ​
  let defaultAttributes: [NSAttributedString.Key: Any] = [
      .baselineOffset: NSNumber(value: baselineOffset),
  ]
  ​
  let middleAttributes: [NSAttributedString.Key: Any] = [
      .foregroundColor: UIColor.blue,
  //    .strikethroughStyle: NSNumber(value: NSUnderlineStyle.single.rawValue)
  //    .link: URL(fileURLWithPath: &quot;&quot;),
  ]
  ​
  let part = NSMutableAttributedString(string: &quot;Lorem ipsum\n&quot;, attributes: defaultAttributes)
  ​
  let middlePart = NSMutableAttributedString(attributedString: part)
  middlePart.addAttributes(middleAttributes,
                            range: NSRange(location: 0, length: middlePart.length))
  ​
  let string = NSMutableAttributedString()
  string.append(part)
  string.append(middlePart)
  string.append(part)
  ​
  // Remove last newline
  string.replaceCharacters(in: NSRange(location: string.length-1, length: 1), with: &quot;&quot;)
  ​
  print(string)
  ​
  let label = UILabel()
  label.backgroundColor = .white
  label.numberOfLines = 0
  label.attributedText = string
  label.sizeToFit()
  label
  </code></pre>