问题
From what I understand as explained in the answer to this question you can resize which ever component on the storyboard for any device that you want, well that right there is the where the problem occurs.. I have an image which the regular resolution of it is : 353x229 and this image looks huge on the iPhone 4s screen so I want to resize it to 300x194 only on the 4s screen and this is how I do it :
First I click on the Vary for Traits button, then I click on the image and then click on the "Show the Size inspector" on the right side and from there I change the "Width Equals" to 300 and "Height Equals" to 194 and then I click on "Done Varying".
But the problem is the image is resized for every single device ! Even the iPad ! I don't understand why this is happening and how am I supposed to stop this from happening?
回答1:
Perhaps by now you have figured it out. But in case others have a similar problem, here's my 2 cents:
I was facing a like problem: a label needed to have a different height for iPhones and iPads. But every time I changed the height of the label on the iPad using vary for traits, it also changed the height on the iPhone.
Here's what I did to fix it:
- Select the object (in my case, a label)
- In the Size Inspector, double click the constraint you want to change for a different device
- Click on the + sign next to Constant.
- Select the appropriate traits (in my case, regular height+width for iPad) and add the variation.
- Now, underneath the Constant dropdown menu, you will now see your different layout for the corresponding device.
- You can now change the size of the respective constraint.
Please note that you have to do this for each constraint you need to change. I realise that it should also work by selecting the desired device and click Vary for Traits. But I think it's buggy and so this is an alternative way of accomplishing the same thing.
回答2:
When you select vary for traits check the box for width while iphone4 selected. All devices in blue box will be effected if any constraint is inserted then. iphone4s screen width is compact in portrait mode and ipad's is regular. While changing the size dont do it by size inspector rather add constraint of position, height and width. So after this you need to go back in ipad's mode and select vary for traits and width checkbox, then click somewhere else. Here you will modify the position, height and width in constraints that can be found in size inspector by clicking edit.
来源:https://stackoverflow.com/questions/40116935/vary-for-traits-not-working-as-expected