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.
Related
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.
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 :)
I'm attempting to build a view (iPhone only, portrait view only) using adaptive layout. It should all be on a single screen (ideally no scrolling). I've managed to get it working (reasonably) for the iPhone 5 - 6+. However, my issue comes with the 4s.
I'd like, on the iPhone 4s to have the center image go away, which I thought I could use size classes, but it doesn't seem so for the various iPhones in portrait mode (only if I switch orientation).
Additionally, I'd like there to be more padding between all the elements on the 6+ while spacing remains the same on the 5 and 6.
No matter what sizes all iPhone in portrait mode is regular height compact width so size class won't help you here.
To change padding constraint
make the ones you want to change IBOutlets
and in viewDidLoad for example change the NSLayoutConstraint's constant value based on screen height.
For iPhone 4S you can
hide the center imageView
deactivateConstraints all it's constraints
and activate new constraint between the view above imageView and below imageView if needed
iPhone 6S Plus's screen is very big compared to other screen sizes. I can't seem to find a good way to handle the font size of a label without adjusting the size programmatically.
How can I adjust the font size of a label so that it looks smaller on an iPhone 5 and bigger on an iPhone 6 Plus?
Don't change font sizes for the iPhone 6 or iPhone 6+.
People buy these phones to see more content. The 6+ displays things slightly bigger than the other phones anyway (yes, it has bigger pixels, not just more pixels), and if a user wants an even bigger display they can switch the whole phone to zoom mode (both 6+ and 6; this turns a 6+ into a large 6, and a 6 into a large 5).
Just use autolayout to position things relative to the screen size.
You can't target iPhone 6 Plus using AutoLayout because it's not meant for hardcoding sizes. You either need to use code and do something like this:
if UIScreen.mainScreen().bounds.size.width == 375 {
// iPhone 6
label.font = label.font.fontWithSize(20)
}
or just create a invisible view and set top and bottom constraints to it.
I think it is better to use adaptive fonts (here is an example, section Adaptive Fonts)
I've been working on a specific app for a while now and everything was good. But upon all this news of the iPhone 6 and the new Xcode, everything has just become confusing. Using Auto layout and designing for the iPhone have just become the most complicated thing to do. Every time I add constraints my images just triple in size. When all I want is to resize them to fit rationally across all the iPhone platforms(In portrait mode). For example I would like for certain images to grow as I work From the iPhone 5 to the 6+. Does any one know how to do this?
What do you mean triple in size?
Easiest way to have an image view scale is do the following:
Add it as a subview to the view of your view controller
Pin it at the top, left and right, leaving height unconstrained
Add an aspect ratio constraint, so that it can automatically calculate its height based on the width it gets