AutoLayout Constraints -- All Devices

Hey,


I've built an iOS Application before but i had taken a few years off from App Development but just recently I've started again and I'm having a problem with the AutoLayout. When I drag a label onto the storyboard, i set up the constraints as advised by Apple walkthrough but when i switch interface devices it changes (i.e it doesnt stay centered.) what am i doing wrong?

Replies

"set up the constraints as advised by Apple walkthrough” - no idea what this means. You should set up the constraints the way you want it, not the way some other UI had it. If you want the label to stay at the top, then add a vertical spacing constraint to something above it. If you want it centered horizontally, then add a constraint to center horizontally in the container (superview). etc.

Could you describe precisely the constraints you have set ?

If you have aligned the label on the vertical middle, it should stay centered. But if you have position to the leading edge for instance, that will not maintain centered when you change device.

I’m sorry for the confusion when I said “set up the constraints as advised by Apple walkthrough” I did mean the Auto Layout guide not walkthrough on the Apple developer Guides and Sample code. I have a couple of screenshot and il see if I can link them from a image upload website to show you what I mean. But if I can’t il explain below.


I can set the label to the middle of the screen on iPhone X but when I switch to iPhone 8 Plus for example, the label is moved to the left and moved at the top of the screen but It’s not centered.


https://imgur.com/a/w3bI1eq



---

Edit: I think ive managed to do it now, and I'm not getting any red errors about the constraints and the images are included in the link provided in this post. Would this stay in position on all devices? Thank you for helping, It's much appreciated.

Good news for you if you solved.


Don't forget to close the thread by marking your own answer as correct.