6

I am trying to use the very for traits feature on xcode 8.2.1 but when I change the layout of one size class using the 'vary for traits' and then 'done varying' when finished it is in fact changing the layout of every size class in my storyboard.

e.g. I try to change the constraints on an ipad w: R, h: R by selecting vary for traits, turning the bar blue at the bottom. I make the necessary changes and click 'done varying' which changes the constraints. But then if I choose another device size such as iphone 7 then the adjusted constraints are also applied to this size class. How do I stop this from happening?

To clarify I have 'Use trait variations' & 'Use Autolayout' selected in the storyboard.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ryan.H
  • 361
  • 4
  • 19

1 Answers1

11

When you start varying for traits, the new UI elements you add are only added to the current trait collection (w: R, h:R in your case). But if you're changing existing elements, they will change for all variations, unless you specifically add a custom configuration (see screenshots).

enter image description here

silicon_valley
  • 2,639
  • 2
  • 16
  • 20
  • Thanks. So would moving elements on the view controller not work in 'vary for traits'? – Ryan.H Jan 12 '17 at 14:44
  • No, that is the same as changing an existing element. But if you want to have elements at different positions depending on trait collection, you just need to hit the little + next to the constant and introduce a new value for the specified trait collection (see screenshot above). – silicon_valley Jan 12 '17 at 18:32
  • 1
    How do i position the element differently for same trait collection. For e.g: iPad pro 12.9" and 10.5" both falls into same size class as well. – Kalaivani Jul 14 '17 at 09:36
  • Unfortunately that isn't possible in interface builder. You can only do this in code by adding outlets to the constraints and setting the values based on the view's width or height. – silicon_valley Jul 15 '17 at 10:14