So I have an image view and a button. I need the image view to be the correct size (not look squished or stretched) on all devices and more importantly I need it to be the s
In my constraints, I needed to uncheck "relative to margin".
You need to do 2 things:
Setting Up Your Constraints:
Choosing Your Scaling:
You can view the constraints that have been created for you. In the document outline, you should see 4 constraints under your image view:
Click on a constraint and then view them in the Attributes Inspector on the right. Here are the 4 that I created:
Not sure I understand "exactly" what you're after but if you want to drag an image view into the controller, and that image view to automatically fill the whole view controller background: just drag the image view component into the view controller window.
Thing is: if you see a blue bounds line around the view controller, before you drag, the image view won't fill the view controller.
You need to click anywhere on the background in the view controller pane, so the blue bounds line disappears, only then, will the image view you're dragging in, fill the whole controller background automatically.
If you find, using previews, your pics are getting squished or stretched, then, just go to the "Resolve Auto Layout Issues" menu, and click "Add missing constraints" - then all should resize to look ok on all screens.
This is what worked for me:
View Mode:
Aspect Fill
As constraints for the image:
Align Center X to: Superview
Equal width to: Superview
The 'Equal width' property is the one that scale the image to the size of the screen.
If you want to have the button in a specific position, set constraints from it to the view, the main ones you want to consider are a top constraint and any left or right constraints. So you are telling the view where you want to position the button in relation to its sides.
Hope this helps.