technerd technerd - 1 month ago 90
iOS Question

What is 'Vary for Traits' in XCode 8?

I am using AutoLayout and Size classes, but with release of iOS10 and new Xcode 8.0, there is one new option

Vary for Traits
. Is this replacement of Size Classe for different width and height of devices.

enter image description here

By selection of
width
checkbox, it displays
varying 14 compact width devices
.

enter image description here

By selection of
height
checkbox, it displays
varying 18 compact width devices
.

enter image description here

By selection of both checkbox, it displays
varying 11 compact width regular height devices
.

enter image description here

How to make use of this options ?
Can we use AutoLayout with size classes as like Xcode7.0 ?
If any one has in depth knowledge then please explain it.

Answer

This is just an extension as to how to use "Vary Traits" quickly in your project for adding different layouts in iPad and iPhones.


For example, you need a button having different widths in iPhone and iPad, then it can be easily done and viewed at the same time rather than the earlier Size classes wherein for checking each layout , we had to open the preview and select devices.

I have added a button with fixed width 50.

enter image description here

If we select an iPad screen now, it shows like enter image description here

Now if we want to change the size for iPad, then click on the button in the bottom-right corner "Vary for Traits". Now you are good to go with selecting landscape or portrait orientations as per need. Also select height & width tickboxes.

enter image description here

I am now changing the width constant to 400.

enter image description here

Then as a confirmation, we need to click on "Done varying" button. After which the screen looks like

enter image description here

Now when you go back to any of the iPhone devices, the width constraint will be the same as earlier set in iPhone device.

enter image description here

Comments