iOS Use Vary For Traits Between iPhone Sizes - ios

I have a button that I want to be different widths depending on which kind of iPhone is being used. Obviously a larger width for the 7 Plus, and smaller on down the line. I click the button, click Vary for Traits, choose Height, change constraints for each iPhone, then click Done Varying and build, but it always keeps whatever the last constraint I edited was, no matter which device I run it on.

Vary For Traits has nothing to do with different iPhone sizes. All iPhones (in portrait) have identical traits; there is nothing to vary.

Related

Layout problems on different ios devices

I'm using a storyboard with some compoments like labels and buttons. The problem is that the captions are too big for my mobile display so the last words will be cutted.
I noticed that the font size seems a little bit bigger than in other apps so I want to ask what the default font size is?
And if I reduce the font, however, there may be problems on various devices, e.g. the presentation on an iPhone or an iPad?
Is it necessary to create different storyboards, each one for every device or what is the usual procedure?
There is an option called "minimum font scale" which may be useful, and there is this built-in functionality to adapt your UI to different devices:
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html#//apple_ref/doc/uid/TP40007457-CH19-SW1
And a tutorial from a site that has helped me wrap my head around a lot of iOS concepts (this is the one I used, got updated for ios11)
https://www.raywenderlich.com/162311/adaptive-layout-tutorial-ios-11-getting-started
Solution With Xcode 9:
Xcode story board has an options to separate configuration for User Interface Elements for different size (iPad & iPhone) and different orientation (Landscape and Portrait), which are Any, Compact, Regular integrated with Size Class.
Size class also allows to set different font size for iPhone & iPad.
Follow these steps, for easy under standing, how to use Size class to solve your problem.
Add label in your story board - view controller layout
Select label and open 'Attribute Inspector'
There is a small '+' icon on left side of 'Font' attribute. Click on '+' icon. It will give you a small popover with size options for your label font.
For iPhone it will show you compact width and regular height by default set/selected. Now change/set height and width both as Regular and Click on 'Add Variation', which will add a new variation for font size for iPad (a device with regular height and width).
Change font size from 17 to 40 for variation with 'wR x hR' (As shown in this snapshot)
Here is result of variation in iPhone and iPad

Xcode 8 Vary Traits with autolayout issue

Ok I've finally taken the plunge into autolayout using Xcode 8.
I might conceptually have the wrong idea. However I have a view in IB which has 2 labels a button and an imageview dead center in the view with dimensions 300 x 300 for 6plus and 6 devices.
What I want to do is vary the imageview size for iPhone 5 (SE) so I click Vary for Traits and select height and width then change the values to 150 x 150 click done and the all looks good looking at iphone 5 (SE).
Now flicking back to 6plus and 6 its also resized to 150 x 150 but I want the image size to remain as 300 x 300. Again I may have the wrong idea completely.
I thought the whole point in this is that its varying the size dependant on what is selected i.e. varied.
Vary for traits or size class is not used to change autolayout for different devices, rather it is used to change layouts for Regular and Compact size of (width or height or both).Too many devices come under regular width like ipad pro iphone 7 plus, etc.
same iphone se and iphone6 in portrait mode has same width thats is Compact.
So when you change for one it changes for both.
When you choose vary for traits and select width+height checkbox it shows some devices in blue box it means all those will be effected.
Better do it programmatically, check device type and set size according to it.

different ui items alignment for tablet

I'm new to ios(android dev). I'm using storyboard, and autolayout.
To optimize application for tablet, i used sizes in storyboard regular width regular height.
I want to align ui items on ipad different than on iphone mode. For example, i have a table of textfields that occupy full width on iphone. On ipad i want to place two or three textfields in one cell. How can i make different ui implemetation for ipad, so the logic shoudl stay the same.
I watched https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html#//apple_ref/doc/uid/TP40006556-CH54-SW1
But there is no answer there.
Jenya Kirmiza,
Size Class is what you want :) Size classes were introduced with iOS8 in order to avoid the multiple storyboards for universal applications and yet provide an easy way for the developer to design differrent UI for differrent Devices :)
I expect you to know SizeClasses, In case you are not aware each device in its various orientation falls to one of the sizeClass defined by Apple.
One thing important to note here is that iPad in its both the orientation falls to Regular x Regular size class
Where as all iPhones other than iphone 6S and iphone 6s + will fall to
Copact Width x Regular Height - Portrait mode
Compact Width X Compact Height - Landscape Mode
Iphone 6s and 6s + falls to
Copact Width x Regular Height - Portrait mode
Regular Width X Compact Height - Landscape Mode
Now that you are equipted with the information of all size classes lets nail this issue down. When you open the story board at the center of the screen there is option to decide the size class :)
So go ahead open up your story board when you see it by default will be in wAny wAny mode What it means is whatever the components you add and add the constraint to it will be applicable to all the sizeclasses irrespectively.
Hence you see the textField added at the center of the screen appears center in all the devices may it be iPhone ot iPad.
For explaining Ill add two text fields named Firstname and LastName :)
Lets start adding textFields and constraints to them in storyboard keeping wAny wAny mode.
Now I have added two textFields one below the other covering the whole width of the screen in any any mode :) This will work fine for me in all iPhone devices :)
But I want to allign them side by side in iPad. Now we know that iPad belongs to Regular x Regular sizee class in both the orientation :)
So Simply change the size class in storyBoard
Now when you see you will see two textfields added one below the other already :)
Now select those textfields we want to align them differently isnt it :) So will have to remove the constraints already added to them :)
Now move them place next to each other add constraints properly :)
Thats it now run on iPhone and iPad :) You will textFields one below each other in iPhone and one next to other in iPad :)
iPhone Output :
iPad output :
Hope this helps :)

Simulated Metrics size for "iPhone 5.5-inch" doesn't show the interface correctly in iPhone 6 plus device

I'm using xcode 6.1.1 version and iPhone 6 plus as testing device. I simply add a button at the right side of my xcode user interface, selecting Simulated Metrics size for iPhone 5.5-inch like this :
But when I run this on device the button goes far away from the right edge. Like this (Snap shoot from my device):
But when I select Simulated Metrics size for iPhone 4.7-inch like this :
It shows accurately in my device. Like this (Snap shoot from my device):
I tried with selecting and un selecting Auto Layout & Size Classes but do not get any clue. My device is 5.5 inch iPhone 6 plus. I even recheck it from my iPhone's packet and by IMEI Number. My question is why it is acting like iPhone 6 interface?? Is it for any reason of retina display or non retina display??
Thanks a lot in advanced.
My button's Constraints:
Select the button/ view you want. Then simply use the shortcut ⌥⇧⌘=. This will Reset to Suggested Constraints.
For this to work successfully, try moving your button to the suggested areas, i.e. move the button/ view to the top right corner like you have till the dotted blue lines appear.
Once done it should show what you expect on the interface builder but to be sure test on the simulator and/ or Device.
You need to add the proper constraints. Using simulated metrics is only for setting things up in IB, it has no effect on what the view looks like at run time. You should leave that setting at inferred.
If you don't add constraints yourself, the system adds them for you, and it adds top, left, height, and width constraints; that is not what you want. You need to add constraints to the top and right side. If you do that, the button will appear with that spacing to the right side, no matter what size screen you're using.
I think you should use constraints to solve the problem but i don't know the exact cause of this
Ctrl + drag from the item to the border in the storyboard to add constraints

Xcode Layout constraints: selecting divisions

I want to have two different layouts. The first layout must be applied to iPhone-3.5inch, and the second one to all the other device sizes. However, the layout I set for the compact width/compact height does not seem to take over the other layout even when I test with an iPhone-3.5inch. How can I make the first one be applied to a small device, while the other to the bigger ones?
according to documentation compact width/compact height is size class for All iPhone models except iPhone 6Plus In landscape mode.
If you want to know whether the device is with 3.5inch screen you must do it in code.

Resources