Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Chapter 2 Tiki Gods label centering problem

I placed a label on the view and dragged it to the center (horizontal and vertical lines appeared when I dragged it to the center of the view)  but when I save and run the simulator the label "Hello, World!" is not centered in the simulator.

I'm running the latest Xcode v4.5.2

Is there a setting that by default is incorrect?
Thanks,
Brian

Comments

  • also show>>Frame Rectangle x=0 y=20 the label in the simulator looks centered horizontally but not centered vertically. Vertically the label is lower.
  • This is almost certainly a conflict between the "classic" iPhone screen size and the new iPhone 5 screen size. You might have your nib file configured for one size, but are running the simulator on a different size. Both of these settings are switchable, of course

    So what happens is that you may have an object that is vertically centered in one view, but shifts up or down in the other. The reason is that the nib problem contains a constraint that is pinning the object's vertical position to either the top or bottom of its parent view, or to another view. What you want instead is a constraint that pins its vertical center to its superview's vertical center. You'll learn more about constraints as you go through the book. 

    The short solution is this:
    - Select the object you want centered.
    - From the menu, select Editor > Align > Vertical Center in Container.

    Then build and run in the simulator. The object should be centered vertically, no matter which device you've selected in the simulator's menu.
  • In my case I also had to delete a constraint that put the label at 263 pixels in Y that created itself when I put the label on the View to begin with.
Sign In or Register to comment.