Custom popup: UIView or UIViewController?

My apps adds buttons at runtime and each of them has to open a popup.

Unfortunately Apple doesn't let you add a custom view to a UIAlertController (instead of the message) and people highly advice against trying to hack it it because it might break in future iOS versions, which means that I'm going to have to create my own custom view.

The new view has to act exactly like a popup, so:
  1. Displayed on top of the calling UIViewController

  2. Don't allow clicking through

  3. Close/remove the view again by clicking the "close" button

My question:
What should I use for that? A UIView in an extra .xib file (instantiate at runtime) or a new UIViewController in my existing .storyboard file (create some type of "show" segue at runtime)?
This may be just a problem of preference, but I would choose UIViewController.
But the UI of which can be put in a .xib or in its own .storyboard or in the existing storyboard, or you may construct it programmatically as in UIAlertController. Though I would not use segue.

With using UIViewController, you can present it as well as UIAlertController and can utilize any animation effects prepared for view transitions.
In fact, UIAlertController is a subclass of UIViewController, so if you make your custom popup as a subclass of UIViewController, it may be easier to switch from UIAlertController to your custom popup.
Thanks for your reply! Any reason why you don't "like" the "instantiate UIView" way?
I know how to do it that way but I also know that you have to add that new view as a child and I'm not sure how that would work as a popup that's supposed to be displayed above everything. If this was the preferred way of doing it, then I'd have to look into that more, that's why I asked this quesiton.

When would you recommend using a UIView over a UIViewController? When it's just a really small thing that's added, so filling less than half of the screen? Or does it depend on what it's added to, so if it's basically a stand-alone thing?

I don't need any animations, it's fine if it just "pops" into existance, it's more important that it looks like a UIAlertController, which is going to be "fun" to replicate.

so if you make your custom popup as a subclass of UIViewController, it may be easier to switch from UIAlertController to your custom popup

Doing it that way I'd subclass UIViewController of course (and create a new scene in storyboard) but sorry, what do you mean exactly? The new popup is going to be called by a button that's created in a regular UIViewController.

what do you mean exactly?

When you show a UIAlertController, you would write something like this:
Code Block
let alertController = ... instantiate `UIAlertController`
... set up `alertController`
present(alertController, animation: true, completion: nil)

With keeping this flow, you can write something for your custom popup:
Code Block
let customPopup = ... instantiate your custom popup
... set up `customPopup`
present(customPopup, animation: true, completion: nil)


I see, it just looks similar.

Any reason why you don't "like" the "instantiate UIView" way? When would you recommend using a UIView over a UIViewController? When it's just a really small thing that's added, so filling less than half of the screen? Or does it depend on what it's added to, so if it's basically a stand-alone thing?
Custom popup: UIView or UIViewController?
 
 
Q