title: Swift 4 - PDFAnnotation text (or UITextField) to be the size of the text
body: <p>I have created a PDFAnnotation Text Widget and everything is working great, its multiline, so what I am trying to do set the size of this Annotation to be the size of text...does this make sense? How would I do that?</p>
  
  <p>Here is my Annotation:</p>
  
  <pre><code>let page = pdfView.currentPage
  
              textAnnotation = PDFAnnotation(bounds: CGRect(x: 300, y: 200, width: 600, height: 100), forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
  
              textAnnotation.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
  
              textAnnotation.font = UIFont.systemFont(ofSize: 80)
  
              textAnnotation.fontColor = .red
  
              textAnnotation.isMultiline = true
  
              textAnnotation.widgetStringValue = "Text Here"
  
              page!.addAnnotation(textAnnotation)
  </code></pre>
  
  <p>How do I make the size of the text like in the native tool? Or how I do this to a UITextField because I can probably do more or less the same thing.</p>
  
  <p>Still got nothing on this....its super hard.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Still have made no process on this. But after reviewing the native iOS PDF Annotations, it appears it does not make the text field long in width, but goes to the next line and makes the height of the text area bigger....I have my PDFAnnotation set to isMultiline, but when I goto the next line I can't see it because my height is only 100.0....So How would it make goto the next line and increase the height of the text area?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I created my own custom PDFAnnotation</p>
  
  <pre><code>class TextAnnotation:  PDFAnnotation {
  
      var currentText: String?
  
      override init(bounds: CGRect, forType annotationType: PDFAnnotationSubtype, withProperties properties: [AnyHashable : Any]?) {
          super.init(bounds: bounds, forType: annotationType, withProperties: properties)
  
          self.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
  
          self.font = UIFont.systemFont(ofSize: 80)
  
          self.isMultiline = true
  
          self.widgetStringValue = "Text Here"
  
          self.currentText = self.widgetStringValue!
      }
  
      override func draw(with box: PDFDisplayBox, in context: CGContext) {
          UIGraphicsPushContext(context)
          context.saveGState()
  
          let paragraphStyle = NSMutableParagraphStyle()
          paragraphStyle.alignment = .center
  
          let attributes: [NSAttributedString.Key: Any] = [
              .paragraphStyle: paragraphStyle,
              .font: UIFont.systemFont(ofSize: 80),
              .foregroundColor: UIColor.red
          ]
  
          widgetStringValue!.draw(in: pageBounds, withAttributes: attributes)
  
          context.restoreGState()
          UIGraphicsPopContext()
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
  }
  </code></pre>
  
  <p>I noticed that the draw method gets called every time I type something, so what I tried to do is compare self.widgetStringValue against the variable currentText but when I try to changed the width if they do no equal each other, it doesn't do anything.</p>
  
  <p>Maybe I can create a delegate method and call it in my ViewController to remove / add the Annotation again...or try to change the bounds from there.</p>