How to center a picture depending on the screen size? (solved)

Hello, I'm new on developing for iOS and I have a question: Is there a way to center a picture depending on the screen size? Because I've tried to add constraints in the picture, but when I view as an iPad Pro, the picture becomes larger and I don't want that cause it loses a lot of quality. So, I would like to center that picture to prevent a low quality on it. Of course, that would means it won't have the same margins as an iPhone 4s for example.


Thank you in advance!

Accepted Reply

If you set constraints for center horizontally and vertically (you may specify an offset to set it a bit higher than vertical middle for instance), that should do it.


What constraints have you defined ?


Possibly, you could constrain the image dimensions.

Replies

If you set constraints for center horizontally and vertically (you may specify an offset to set it a bit higher than vertical middle for instance), that should do it.


What constraints have you defined ?


Possibly, you could constrain the image dimensions.

Thank you @Claude31. So, I already set constrains for center horizontally and vertically, but I don't see where can I specify that offset. This is how I center the picture: https://i.imgur.com/dEQYoBm.png


And of course, if I view the app as an iPad, this is how it looks: https://i.imgur.com/jVD4Q9Z.png


I've also tried to add the Width and the Height contraints, but it's not doing anything because it says "Horizontal position is ambiguous for "field_1" and then another warning: "Auto Layout Localization - Leading and trailing constraints are missing, which may cause overlapping with other views".


The app also has text fields, buttons and labels, so that's why I'm getting a warning about the "field_1". Am I doing something wrong?


Edit: I've just figured it out! A video helped me about how to do it. Thank you so much again, Claude.