How to make a popup window with an image SWIFT

一曲冷凌霜 提交于 2019-12-03 08:40:26

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!