Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a popup window with an image SWIFT

I was wondering how to make a popup window similar to this example:

The origin window is full of buttons that when is selected will then pull up the image I desire to use.

like image 772
Marcello B. Avatar asked Jan 09 '23 05:01

Marcello B.


1 Answers

I would simply create a reusable UIView component and everything you need as a subview, such as a UIImageView for your image, a UILabel or a UIButton in the top right. Here is the process to show it:

  1. Create a UIView that takes up the full screen, make it black, and maybe 0.5 alpha.
  2. Create another UIView which is your primary pop-up view, make it slightly smaller than the previous view, but make sure both of these views are subviews of the parent subview.
  3. Add the desired elements on to the pop-up view as subviews, I would even suggest creating a UIView subclass if you plan to use this a lot.
  4. To present the pop-up, make sure both views are set to hidden = true when created and so that when a button is selected, you can set them to hidden = false
  5. If you would like them to be animated, simply start them off with alpha = 0.0 and use something like UIView's animateWithDuration and set the pop-up view to alpha = 1.0

There is a lot of little details you can change to cater to your needs, but this is the basic structure on how to accomplish your goal.

Check out UIView animation methods here.

like image 183
tfrank377 Avatar answered Jan 18 '23 17:01

tfrank377