pedron
pedron

Reputation: 237

Incorrect display for Objective-C/iPhone 'Hello World' app

I am running the 'hello world' app from: https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/

I am seriously at like step 2, but I can't figure out this strange little thing, and I don't want to move on until i do. I'm a bit stumped, and I've been poking around all over.

I created a view controller with a single label. It looks like this: Screenshot of view controller!

Nice and centered, right?

Well, when I run the ios simulator I get this:

ios simulator!

I can't figure out why it's off to the right like that. I checked to see if for some reason it was running as iPad app so the X and Y domain were off, but it appears that it is running as iPhone 4s, or at least as much as I can tell. How to get this centered?

I am running Xcode 6 beta version. I have a friend who did this without a similar issue, so I don't think it's a bug in the IDE.

Upvotes: 1

Views: 125

Answers (2)

Heisenberg
Heisenberg

Reputation: 367

I think you have to zoom out the simulator. You can do this by pressing "command + 3" while the simulator is running.

Or, you could also do it like this: screenshot

Upvotes: 2

Andrew Robinson
Andrew Robinson

Reputation: 3434

You need to add constraints to tell that label where to be. Research AutoLayout constraints: Autolayout Guide

Currently, that label is positioned exactly where you told it to be. Since you're in the Any : Any size class, the origin of that label is something like say x: 310, y: 300. The iPhone simulator you're running on has a screen area of width: 320 height: 420, so if your label has a width of 20, half of it would be off the screen.

If you had set constraints for the view, autolayout would have dynamically adjusted the origin of your label for you.

Upvotes: 2

Related Questions