Create A simple popup with Storyboard Swift

this is what we are going to build

popUps can be used to easily display overlays within your iOS apps

Open xcode, create new project
Give you project a name and save it
  1. open main.storyboard
  2. change the background color of the View
  3. add UIView, we will use the view as popup
  4. give the UIView a proper constraints

connect the view to your ViewController as IBOutlet

lets add Button so that when we click the button we call the popupView, then connect button to the ViewController as IBAction

now what we do is hide the popUpView when the ViewController loads and give the popUpView rounded corner for better looking

popUpView.layer.cornerRadius = 24

popUpView.isHidden = true

so now when the Button is clicked show the popUpView

popUpView.isHidden = false

now how do we hide the popUp again? well you can add a button to the popUpView and hide it again

but now lets add a UITapGestureRecognizer when we tap anywhere on the screen the popUpView disappears

let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))

view.addGestureRecognizer(tap)

@objc func handleTap(_ sender: UITapGestureRecognizer? = nil) {

/// handling code

}

there you go, you have your PopUpView.

--

--