VirtualProdigy
VirtualProdigy

Reputation: 1687

iOS Swift, Constraint pushing view off sotryboard

I'm working on my first swift app and I found out quickly that I need to use constraints to properly layout my page. So far I'm running into two issue.

The first one is that after adding some constraints, my view is pushed off the screen on the storyboard, but it looks fine(outside of my second issue) in the Assistant editor.

My second issue is that on some phone sizes the constraints are causing the text fields to expand when viewed in the Assistant editor and on an iPhone 6s test device.

I've added some screen shots below. Any help with this issue would be really appreciated.

storyboardconstraintsassistant editor

Upvotes: 0

Views: 778

Answers (1)

Said Sikira
Said Sikira

Reputation: 4533

Each time you add a constraint in storyboard, it is not automatically applied to your working view. You may think it should be applied immediately, but try to think think like this. If you have a view, and you apply height constraint (for example) and if Xcode applied it automatically you would get a view of width 0, since you haven't applied width constraint. That's why you need to tell Xcode to update constraints explicitly.

So when you want to update constraints, select view you want to update and go to Resolve Auto Layout issues, and click on Update Frames. This is located in the bottom right corner of your storyboard. It looks like a small triangle between two lines. Here you can update all views or just selected views.

Resolve autolayout issues

For the second issue, you need to apply fixed width constraint to your stack view, instead of adding leading and trailing constraints. By doing that stack view will have the same width on each device.

Upvotes: 2

Related Questions