title: how to determine the font size of the text from the height, in swift？
body: <p>I need to add a text watermark to the image. 
  The height of the text varies with the height of the image. 
  Now I know the height of the image, and I know the height of the text. 
  How do I know the font size of the text?
  In short, how to determine the font size of the text from the height？
  Now my solution is as follows. Does anyone have a better way? 
  Thanks!!!</p>
  
  <pre class="lang-swift prettyprint-override"><code>/// - Parameter height: target height for font
   func textFontSize(from height: CGFloat) -&gt; CGFloat {
          var fontSize: CGFloat = 30
          var textFont = UIFont.systemFont(ofSize: fontSize)
  
          while (textFont.lineHeight &lt; (height * 4 / 5) ||
              textFont.lineHeight &gt; height){
  
              //decrease font size
              if textFont.lineHeight &gt; height {
                  fontSize = fontSize - 0.5
  
              // increase
              }else if textFont.lineHeight &lt; (height * 4 / 5) {
                  fontSize = fontSize + 0.5
              }
  
              textFont = UIFont.systemFont(ofSize: fontSize)
          }
          return fontSize
      }
  </code></pre>