Autolayout - How to Change width spacing between i

2019-08-21 16:55发布

问题:

Ok, I have been pulling my hair out for a few days now and thought I would ask the community how to deal with width sizes or the gaps between buttons in xcode 6.4 or 7 (tried them both).

Ideally I want 2 buttons near the bottom and they need to scale properly based upon iPhone portrait mode.

I have added the 1x, 2x, and 3x pngs of the button to the asset system and my auto layout is set for wCompact hRegular which from what I understand allows you to target all iPhone devices in portrait mode.

So after adding my buttons I had it do add missing constraints which added a few and seemed to work pretty good but the issue im running into is the gap spacing between the 4.7 inch and 5.5 inch and how to adjust each one of those separately in interface builder if possible.

See the image below where I outline the gab space and its quite huge for the 5.5 inch.

Also it would be awesome if I could use bigger images for the bigger phone but thats another subject I guess.

Since I cant post images here here is the link to the story board

回答1:

Take a look at this repository..

https://github.com/mahesh-agrawal/Test-Autolayout-Buttons-Spacing

i have added required constraints to make the gap between the buttons dynamic for all devices. also i have made the width and height dynamic by giving proportional width height.

I have taken two views and given them horizontal spacing 0 and equal width and leading and trailing required for each. and then i have taken two buttons in each and managing width of button with proportional to the views so they will increase accordingly and also the gap will increase accordingly. Test in all devices.