1. Add an new ViewController to your project Main Storyboard

  2. Create a new Swift file named RightMenuViewController with the Subclass UIViewController

  1. Assign the Class to the newly created ViewController as shown below. Also make sure you add the Storyboard ID for the ViewController as RightMenuID. This ID will help us to refer to the ViewController while opening the popup menu


  1. Add a Bar Button Item on the ViewController where you wish the popup menu to appear as shown below. We will refer this ViewController as HomeViewController.

  1. Create an action reference to the button on the HomeViewController as shown below.

This will create a new function with the name rightMenuButtonTapped on the HomeViewController. Here we can write our code to open and close the popup menu

  1. Add below code to the function created in above step

Above code creates the RightMenuViewController as a Child View Controller and shows it when the Right Menu Button is tapped. On tapping the same button again, the code checks if there are already any child view controllers being shown and if yes it removes them all.

This completes the basic functionality of showing and hiding the popup

However if you also want the popup to disappear when the user taps anywhere outside the popup then add below code to the RightMenuViewController

Finally it is also important to properly place and format your popup menu.

Now just compile and run the code. You will see the popup menu as shown below after clicking the Right Menu Button


Download PopupMenu Source Code

Leave a Reply

Your email address will not be published. Required fields are marked *