How do I use auto-scaling for all screen sizes?

The main navigation view of my app uses UIButtons with background images. I am using autolayout in IB to lay out a view.

I want the view to look the same (or similar, just scaled appropriately) on iphone 4, 5, 6 and 6plus. I've tried using vertical and horizontal constraints, but don't know how to use aspect ratio constraint.

Here's what the iPhone 5 looks like.

view on iphone5

Here is what I got so far on the iphone 6

view on iphone6

This is what I want it to look like on iphone 6 / 6plus.

view on iphone6 ​​- correctly laid out

How do I use autoplay to scale the view so that it looks the same or the same for all iphone screen sizes?

+3


source to share


2 answers


I did a bit of tinkering and I believe I have found a solution. I'll demonstrate how to do this for two large squares about the middle of your view.

Here's a reference image:

enter image description here



First, you need to create a container (my blue view) that spans the entire width of the supervisor, and has a height equal to or greater than your inner squares (orange).
This view requires the following constraints: Align Center X to Superview, Align Center Y to Superview ( OR ) to give it the desired Y position), Height Equals: [square height], Trailing Space to Superview, Lead Space to Observe.

The inner orange squares must be placed inside the container and must have the following restrictions: Center X to Superview, Leading Space to Superview (value = space between square and supervisor edge), Trailing Space to [other view] (value = space between squares). Select two squares together and add aspect ratio constraints equal width and equal height.
The items in bold depend on the selected square. The left one should have leading space to view and move the space to another view, and the right one should have these constraints.

This will give you the desired effect when autodetecting.

+4


source


A bit late to the party, but I think this will help someone in the future. Here's what I think is the best way to do it. I will write down the steps I followed to achieve the desired result.

1 - Add both squares to the view controller as shown below.

enter image description here

2 - Now select the first cube and select the "Pin" menu at the bottom of the screen. Add top and left constraints.

3 - Now select the second cube, the one on the right, and add top and top constraints to it from the Pin menu.

4 - Now select the first cube and cntrl-drag from inside the cube to the view controller. Now choose "Equal Widths" from the menu. Confused huh? Hold on. enter image description here



5 - Now double click on the "Equal Width" constraint bar and a menu will appear. In the "Multiplier" field, change the value to 0.4

6 - Repeat steps 4 and 5 for the right cube.

7 - This is how the result will look at different iPhone sizes. (The first is a 4 "device, the second is a 4.7" device, and the third is a 3.5 "device.) PS: The bottom is cropped because the screenshot is from the preview :)

enter image description here

UPDATE (16/01/2018)

In step 4, choose "Equals Width" and choose "Aspect Ratio". Skip step 5 after that.

+1


source







All Articles