Question

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?

Was it helpful?

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:.

OTHER TIPS

It looks to me as if you have the GUI designer aligning base upon the center center of your image view. When you do it in code, it is going to align based upon the top left of the image view.

Further, your code places it at a y of 50, where your GUI designer is showing a y coord. of 192.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top