title: How do I get line heights of UITextView when using UIStringAttributes in Xamarin Forms iOS?
body: <p>I have a problem with setting <code>UIStringAttributes.Font</code>.</p>
  <p>Before setting it, the system defaults to <strong>Helvetica 12pt</strong>, with a line height of 13.8.</p>
  <p>This line height seems accurate as shown by the image here:</p>
  <p><a href="https://i.stack.imgur.com/PReZn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PReZn.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/uFGSP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uFGSP.png" alt="enter image description here" /></a></p>
  <p>However if I set the <code>UIStringAttributes.Font</code> property with <strong>Arial 17pt</strong>, the line height of 18.99 seems inaccurate as shown here:</p>
  <p><a href="https://i.stack.imgur.com/IKypM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IKypM.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/JGtxy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JGtxy.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/1U4ML.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1U4ML.png" alt="enter image description here" /></a></p>
  <p>My code is as follows:</p>
  <pre><code>void SetAttributes(string text)
  {
    NSMutableAttributedString astr = new NSMutableAttributedString();
    UIStringAttributes attrs;
    NSAttributedString str;
    CheckBox cb;
    string[] lines;
    string line;
  
    lines = text.Split(&quot;\n&quot;, StringSplitOptions.None);
    for (int i = 0; i &lt; lines.Count; i++)
    {
              cb = _checks[i];
              line = lines[i];
  
      if (i + 1 &lt; _checks.Count)
        line += &quot;\n&quot;;
  
      attrs = new UIStringAttributes();
      attrs.ForegroundColor = cb.Color;
  
      ////////////////////////////////
      //COMMENTING THIS LINE OUT ALLOWS A CORRECT
      //LINEHEIGHT TO BE GIVEN IN DRAW METHOD
      attrs.Font = Control.Font;
      ////////////////////////////////
  
      str = new NSAttributedString(line, attrs);
  
      astr.Append(str);
          }
  
    Control.AttributedText = astr;
  }
  
  public override void Draw(CGRect rect)
  {
    double baseline = editor.Padding.Top + Control.Font.Ascender;
    double movingBaseline = baseline + BOTTOM_MARGIN;
    double scrollY = Control.ContentOffset.Y;
  
    double _lineHeight = Control.Font.LineHeight;
  
    //get graphics context
    using (CGContext g = UIGraphics.GetCurrentContext())
    {
      for (int i = 0; i &lt; _lines.Count; i++)
      {
          CGPath path = new CGPath();
  
        //set up drawing attributes
        g.SetLineWidth(0.5f);
        UIColor.Black.SetStroke();
  
        //add lines to the touch points
        path.AddLines(new CGPoint[] { new CGPoint(0, movingBaseline - scrollY),
                    new CGPoint(300, movingBaseline - scrollY) });
  
        //add geometry to graphics context and draw it
        g.AddPath(path);
  
        g.DrawPath(CGPathDrawingMode.Stroke);
  
        //tying this to the control.baseline hopefully should help
        //to avoid accumulating rounding errors
        movingBaseline = baseline + BOTTOM_MARGIN + (_lineHeight * (double)(i + 1));
      }
    }
  
  
    base.Draw(rect);
  
  }
  </code></pre>
  <p>I've tried:</p>
  <ul>
  <li>1 other font, <strong>Consolas</strong> -&gt; height still wrong</li>
  <li><code>NSString(text).StringSize</code> -&gt; gives height of 19 which is wrong</li>
  <li>Setting <code>ParagraphStyle.LineHeight</code> in <code>UIStringAttributes</code> so I can control the height, but unfortunately it is not settable because Xamarin hasn't implemented a setter</li>
  </ul>
  <p>Any ideas?</p>