Aeradriel
Aeradriel

Reputation: 1232

Constraints set but views not placed correctly

I'm having an issue with constraints. I set constraints on my UI elements that you can see below. For each I set x, y, and height/width for some. When I click "Update the Frames", everything is ok and the views are placed at the right place. But on the Preview (right window on the screenshot) and in the simulator, the views are not placed correctly and there is nothing on the screen. When I launch the app on the simulator, I have no warning in the debug console saying that there are constraints conflicts. Same in Xcode, no warning and no error.

Here are my View controller and the set constraints. You can see on the right, the preview for several devices.

xcode screenshot

Upvotes: 0

Views: 57

Answers (2)

Hiren
Hiren

Reputation: 250

you need to design your viewcontroller in all size classes. You design your view controller in w:regular and h:regular which is not for iphone so when you run application,the view will not showing

Apple has introduce Adaptive Layout in ios 8, so refere Size Classes in for more information

Upvotes: 0

jzarob
jzarob

Reputation: 437

Looks like you added the items to the w:Regular and h:Regular size class. The UI Elements aren't in any other size class besides that one. You're not seeing the UI Elements because the iPhone's size class is w:Compact h:Regular.

You need to add the UI Elements to all size classes, not just the w:regular and h:regular.

I recommend the Stanford Course's AutoLayout lecture if you're still having issues, I know it helped me out a ton.

Upvotes: 1

Related Questions