iOS - how to set constraint from iPhone 7 to SE - ios

I've this big problem. iPhone 7 and SE uses the same size classes, so I cannot edit the constraints of SE. When I launch SE simulator, the app isn't optimized..in what way can I solve this problem?

If you have a label that is showing "some text..." on SE. There are a few ways you can solve this.
You could allow that label to be multiline
You could choose different text based on width
You could measure the text and if it's too big, use shorter text
You could pick something that fits on all widths
You could use the auto-font sizing features of labels
You could pick a font size yourself from the width or by measuring.
Constraints/Size-classes are not the only tool you can use for a responsive design.
The point of using size classes is not to solve this kind of problem -- it's to have a completely different UI -- like you show side-by-side panes on iPad and a navigation controller on iPhone.

Related

How do I adjust the font sizes for iPad in iOS? (Clashing elements)

I'm having problems with app elements clashing together on the smaller iPad size. Is there a way to resize the fonts so they're not so large in iPad? Samples below:
App Screen on iPhone:
App Screen on iPad:
If you are using Storyboard, then use auto layout properly to avoid overlapping in smaller screen sizes. Firstly, you should give minimum distance between each element.
Secondly, for LABELS, there is a property Autoshrink in Attributes Inspector which when set to Minimum Font Size gives the ability to shrink the text size with the screen size accordingly.
For Text Field's, there is a property Min Font Size in Attributes Inspector which helps shrink font sizes accordingly.
This can work in conjunction with the answer of #Vikash Kumar
Select your label in your storyboard. In the attributes inspector you will see a small '+' to the left of the font selector. This will allow you to choose size-class specific stuff for your text.
Size classes were added to iOS 8 when Apple introduced Universal Storyboards which let you design for both iPad and iPhone with the same Storyboard file. At the bottom of the Storyboard design window you'll see the (default) 'w Any h Any' button. This gives you access to combinations of the compact and regular size classes. These available combinations let you implement design, say for only the iPhone in landscape, or maybe the iPad in both orientations. You have full control.
For your font related question, you access the size-class control through the '+' sign I mentioned above.
This is a good explanation and tutorial: Wenderlich size classes
and in Apple's explanation: Apple size classes

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

Supporting all iphone sizes

I'm trying to create a iOS app, but I'm stuck on the layout.
I created the home view, but now I see that it's not shown in the right way in the 4S simulator.
I tried with size classes, but it looks like 4S and 6, for example, are in the same size class, and so I can't set a different dimension for views.
My goal is to support all devices, also iPads. Can someone please tell me how to do it?
Size classes mostly used for separation between ipad, apple watch and landscape modes.In potrait mode iphone 4 to iphone 6 all phone device sizes are in same class(regular height and compact width).Autolayout has many different constraints to help you to fit interfaces in same class.You should consider horizontaly/verticaly align, equal width and aspect ratio constraints.They are so flexible for smaller size changes and help you to design adaptive layout.
You should use "Reset to Suggested Constraints" for all views in your View controller. You can also check the simulated metrics for all devices without compiling the the code.
For 4s and 6 by default the size is Inferred. You should try resetting the constraints to check this for iPad as well.
I am just sharing an idea
Option1:
I think You can try adaptive Layouts and in file inspector->simulated Metrics->size-> Inferred. It works in all devices it supports both landscape and Portrait.
Option2: Go for Visual layouts they are easy to understand and they work perfect in all modes of Portrait.
I am think that you use code Instead design in main.storyboard !
for ex: create button with code
(and use Ratio in your code)
by this way i create small app for iPhone & iPad
!

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 :)

Building responsive layouts with AutoLayout

For the past few months, I have been trying to learn iOS development. Most of it has relatively easy, however, one thing has been very difficult for me. AutoLayout. After I grasped constraints, I thought it would be easy, but I am having real trouble getting my layouts to look well on both iPhone and iPad devices. I can design pretty well for iOS. Recently, I was building an app where I put two buttons in the ViewController. on iPhone, I set the constraints of the buttons to equal the width of the screen (plus the screen margin), and set a reasonable looking height to the buttons. On iPhones, my layout looks great, but on iPads (especially the newest iPad Pro), things look horrific. Full width buttons look great on the iPhone, but on iPad they need to be a lot smaller width wise and a lot bigger height wise. Likewise, my images look great on iPhone, but are too small on iPads. In CSS, I could just use MediaQueries, and on Android, resource qualifiers on the values and layouts.
What are my choices here? How can I design my layouts to look nice on both iPhone and iPad when certain dimensions need to be different based on screen size, screen resolution, etc.? Constraints seem to be good for enforcing dimensions, but not adapting them.(Except maybe the Aspect Ratio constraint)
What features of the AutoLayout system can allow me to accomplish responsive layouts among larger screens and Retina resolutions? What are some common tips / tricks for developing responsive layouts.
You can use size classes in order to build for different screen sizes easily. raywenderlich.com has a solid guide on adaptive layouts.
You can use size classes to design differently for iPhones and iPads and also you can use proportional width height to look perfect based on the height ratio of all devices. If you want to choose first option then you can go with any tutorial available but if you want to choose the second option which is the little difficult way but time saving way then you need to really understand the sizes of devices and need to understand what actually proportional width and height constraints do. Thanks.

Resources