Search code examples
xcodecgrect

Get the position of a CGRect in an Interface Builder file


Instead of guessing the float points of a UI element on the screen, is there any tool to tell me the exact position of a UI element in my storyboard?


Solution

  • I am not sure if you have taken a look at the Utilities section in Xcode. It is displayed on the right side. If it is not there, click on the third button of the View section

    View buttons

    And then you can find the ruler tab where you can see all the values of the CGRect you want: X, Y, width, and height.

    Utilites ruler

    PS: In addition to that, ff you want to see the CGRect values of the views on the fly in the Simulator, you can use DCIntrospect, which I find is really helpful for debugging. You can click on the views and see the CGRect values on the top right corner.

    enter image description here