Jeenal Infotech

How to Visualize Alignment Rectangles in iOS/OS X apps?


Both iOS and OS X enable you to overlay views with their alignment rectangles in your running apps. By setting -NSViewShowAlignmentRects to show the alignment rects around the UIView objects in the app.

How to set:

There are two ways to set -UIViewShowAlignmentRects for your apps.

  1. Using App’s Schema
  2. By Coding

1) Using App’s Schema:

To do this using the scheme editor in Xcode:

  1. In the Xcode menu go to Product -> Scheme -> Edit Scheme (⌘ + <)
  2. In Run, the Arguments tab, Arguments passed on launch, click the plus button and enter following argument:
    -UIViewShowAlignmentRects YES (for iOS)
    -NSViewShowAlignmentRects YES (for OS X)

    Note: make sure to prefix with a dash, as shown in Figure 1

Figure 1

  • Finally, Click on Close Button. That’s It.

  Now run your application and you can see UIViewShowAlignmentRects is ON on your console as shown in figure.

Figure 2

2) By Coding:

Add following code snippet into your AppDelegate’s didFinishLaunchingWithOptions method, after that restart the app to take the effect. If you are running the app on simulator then quit the simulator.

Swift 3.0
UserDefaults.standard.set(true, forKey: "UIViewShowAlignmentRects")


[[NSUserDefaults standardUserDefaults] setBool:YES
[[NSUserDefaults standardUserDefaults] synchronize];

Now, If you want to turn that off add the following piece of code:

Swift 3.0
UserDefaults.standard.set(false, forKey: "UIViewShowAlignmentRects") //UserDefaults.standard.removeObject(forKey: "UIViewShowAlignmentRects")


[[NSUserDefaults standardUserDefaults] setBool:NO
[[NSUserDefaults standardUserDefaults] synchronize];

And the next time you run the app, everything would be reversed to original state

9 thoughts on “How to Visualize Alignment Rectangles in iOS/OS X apps?

  1. anonymous

    I simply want to mention I’m new to weblog and absolutely liked you’re blog. More than likely I’m planning to bookmark your website . You really have amazing writings. Many thanks for revealing your web-site.

Leave a Reply

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

Show Buttons
Hide Buttons