Search code examples
iphoneioscocoa-touchcgrectcgrectmake

Trying to position a button programmatically, however not in right position according to X,Y


I'm trying to position a button.

Here is the code for the positioning..

[btnAbs setFrame:CGRectMake(57, 50, 106, 99)];

The coordinates I got are from here:

enter image description here

As you can see the xib stats the x & y to be at 57 and 192, which is where I want the button to be.

However when I run it in simulator, here is where its placed:

enter image description here

Obviously i could keep guessing and guessing the x and y coordinates, but this is very time consuming. So how come it's doing this? Please join the links together when looking at the pics as i need more than 10 reps to post images, or a mod fix this please?


Solution

  • The problem is here:

    Interface Builder view settings

    The “origin” in Interface Builder doesn’t actually affect how the view gets positioned programmatically—it’s just a visual aid. If you click the dot in the top left of that box, the X and Y coordinates will change to the top-left of the view, which are the coordinates you want to pass to -setFrame:.