Create a popup menu in swift

  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

Adding UIBarButton items programatically in iOS

Adding a single Custom Image UIBarButton items programatically

Above code adds a single bar button on the left of the navigation bar

Adding multiple Custom Image UIBarButton items programatically

Above code adds two bar buttons on the right of the navigation bar

Adding a System UIBarButton item programatically


Disable OS Logging in XCode 8

If you run your project in XCode 8 all of a sudden it will start showing lot of strange logs. Many of these logs are not related to your application so don’t worry. They are just OS logs. It does appear to be non intentional because such logs are not going to help us in any way. In fact it makes it much more difficult and frustrating to find the right logs related to App crashes, debug messages, etc.

Fortunately there is a way to disable these logs

Here are the steps

  1. Open your project and navigate to Product => Scheme => Edit Scheme
  2. This will open a dialog box as show in the below screenshot
  3. On the Run Tab, Select Arguments and add the Environment Variable OS_ACTIVITY_MODE with value disable

Disable OS logs