title: Swift: Custom UIAlertController view
body: <p>The <a href="https://developer.apple.com/documentation/uikit/uialertcontroller" rel="nofollow noreferrer">docs</a> say that subclassing UIAlertController is bad</p>
  
  <blockquote>
    <p>The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.</p>
  </blockquote>
  
  <p>So what is the recommended way to have an alert that shows not only a title, message and some buttons but also other stuff like ProgressBars, Lists, etc.?</p>
  
  <p>In my special case I would like to have two different alerts, one that shows a ProgressBar and one that shows a list of error messages.</p>
  
  <p>Currently I am trying to add the ProgressView manually and set constraints:</p>
  
  <pre><code>func getProgressAlert(onAbort: @escaping () -&gt; ()) -&gt; UIAlertController {
      let alert = UIAlertController(title: "Test", message: "Test", preferredStyle: .alert)
  
      let abort = UIAlertAction (title: "Abort", style: UIAlertActionStyle.cancel) { _ in
          onAbort()
      }
      alert.addAction(abort)
  
      let margin:CGFloat = 8.0
      let rect = CGRect(x:margin, y:72.0, width: alert.view.frame.width - margin * 2.0 , height:2.0)
      self.progressView = UIProgressView(frame: rect)
      self.progressView!.setProgress(0.0, animated: false)
      self.progressView!.tintColor = UIColor.blue
      alert.view.addSubview(self.progressView!)
      self.progressView!.translatesAutoresizingMaskIntoConstraints = false
      self.progressView!.widthAnchor.constraint(equalTo: alert.view.widthAnchor, multiplier: 1.0).isActive = true
      self.progressView!.heightAnchor.constraint(equalToConstant: 5.0).isActive = true
      self.progressView!.topAnchor.constraint(equalTo: alert.view.topAnchor).isActive = true
      self.progressView!.leftAnchor.constraint(equalTo: alert.view.leftAnchor).isActive = true       
  
      return alert
  }
  </code></pre>
  
  <p>I don't think this is the way this should be done as manually defining constraints is very prone to errors on different devices. For example, the current code just shows the progress bar on the top of the alert view, but I want it to be shown between the message and the abort button.</p>