简体   繁体   中英

Swift Xcode auto layout constraints only target iphone 6 plus and ipad

The auto layout "picker" looks like the image bellow:

自动布局

But what if I only want to target iphone 6 plus and Ipad?

I use the constraints compact width | any height in order to only target 3.5 - 4.7" displays.

But what should I use in order to only target iphone 6 plus / ipad? - The any width | any height do target them but would that not also overwrite the rules set in compact width | any height ?

What I want to do is to increase spacing between three labels when the app runs on a iphone 6 plus or ipad. Also to note, my app only runs in portrait mode if that matters.

thanks in advance,

You shouldn't categorize autolayout via device, but rather by class sizes. This was a HUGE emphasis this year at WWDC due to the new iOS 9 iPad multitasking feature discussed at the keynote.

I recommend trying the following idea for your layout. Note this is just a visual interpretation of what you need to implement in IB.

All three labels have equal width constraint

|---[first label, maxwidth = x]--[second label]--[third label]---|

This will make all three labels have the same width and be evenly spaced across. This approach helps with all class sizes of compact width | compact height, etc. If you need help finding a way to do even spacing between, trying adding filler views:

|[uiview][first label, maxwidth = x][uiview][second label][uiview][third label][uiview]|

Each [uiview] in this case will have the same width as well with a background color of clear this way the margining between the labels will be even and these views aren't "seen" but help with autolayout.

If you need help with this auto layout implementation please let me know in the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM