iOS - Autolayout/Size classes for buttons - ios

I'm a bit confused about when to use autolayout and/or size classes for certain situations. On my initial view I have 2 buttons, one "continue with facebook" and one "register via email", stacked vertically. I initially set these to have around 70 height and 18pt font, and it looks great on the newer phones, but on the smaller ones they look enormous and combined (with spacing) end up taking up almost half the screen.
So my first thought was to make the buttons a percentage height of the main view or a subview, but things just started getting really complicated really fast: do I use percentages for the margins and spacing as well? Where does it end? It's a lot of calculations.
But I also don't see how it would be useful to use size classes here, since my app is only in portrait mode, and I can't really target say iPhone 5 vs iPhone 6 in that way.
So do I have to bite the bullet and use percentages to get nice looking buttons on all screens, or should I just suck it up and have really fat ones with a big font on the now less-used phones? And when it comes to font size, is there a generally accepted standard set of sizes (for headers and body text, for example) that looks good on all phones?

did you try use an aspect ratio constraint? if you use that then keep the distance from the edges fixed and it should squash proportionately for the different screen sizes

Related

iOS: Buttons sizes relative or absolute?

i wonder what is the best practice for ui design for iOS regarding ui element sizing, especially buttons. In my example all buttons are based on images, no text.
I see two approaches
Absolute Sizes
PRO:
image based buttons do not need rescaling, avoids blurriness
simple setup in interface designer
CON:
buttons look smaller on bigger displays (ipad2 vs. iphone 4) relative to other ui elements
Relative Sizes
PRO:
buttons look better in whole ui appearance across all display resolutions and densities
CON:
buttons may look blurry
interface builder constraints will get a bit more complex
Did i forgot something? Or did i get it wrong?
For now i was designing the ui completely relative to the screen. So lets say a button had the width of 10% of the screen width and an aspect ratio of 1:1. When the ui was completely relative, everything seemed consistent across all devices. But my questions started in the scenario of #2x density buttons. The iphone 4 has a width (portrait mode) of 640 while the ipad2 has an width of 768. Should i create my #2x, 10% button image with a width of 77px or 68px? I would say 77 because downscaling is better than upscaling.
Well, this leads me to my question:
What is the best practice to design the UI? How should we handle the image design for buttons?
Usually the problem is the text got stretched.
You can set the strech area by following this:
https://developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/SlicinganImage.html
If you use gradient and it became blur when stretched, you need to draw the gradient using Core Graphics.
I'd say there's no ultimate approach for laying out image buttons in iOS and it always depends on what you're trying to achieve.
In your case I would recommend the following approach:
Use layout constraints to position your buttons properly. Use only
spacing constraints, no width or height constraints!
Set the images for your buttons (either in Interface Builder or in code). Make sure to provide each image asset in all three resolutions #1x, #2x, #3x.
If you have multiple buttons in a row give each of them a different horizontal compression resistance priority. This ensures that in case your buttons don't all fit on screen one (or more of them) will be scaled down to fit.
When assigning an image to a UIButton, that image will determine the button's intrinsicContentSize. Thus, the button will automatically take the size of the image (if no other constraints with a higher priority are present) and it will only scale down if absolutely necessary (see number 3. above).
This approach is only possible if you still leave flexible spaces next to the buttons. If you intend to split the screen equally into three columns for example and each button should take the whole width of a column you have no other choice but do let the system scale down the images for devices with a smaller screen size. It always depends on whether you can allow the buttons to size themselves or if you need to force a width (or height) on the buttons from their superview.

using Standard Values Instead of constant in Autolayout IOS

I have just started learning IOS Development so my knowledge to it is very little.
I am building my layout for my app. I need my app to run on all devices . I have read somewhere that you should never use a constant magic number when creating constraints and always use standard values. I want to support my app for all resolutions
whenever I set standard value it's '0' so does this means that I have to play with multiplier values to have similar spacing
And kindly let me know when we can use constant value and when we have to avoid.
Most of the times you need to space the views evenly in the screen . This makes the view look similar on all devices (like on a bigger screen it should be equivalent to scaled version of how it looks on a smaller screen).
For Eg. If you need to space 3 views horizontally and equally on a view. If you set the height/width of the buttons to a magic number, say 100 pixels. The 3 subviews would look relatively smaller on a iPhone6+ screen than say on a iPhone5 screen.
This is when you use multipliers. Like height/width of buttons = 0.2 of superview.
On the other hand you need to use magic numbers in some cases.
For Eg. You are creating a canvas on the screen in which the user will draw with a menu panel on the left. You know the menu panel fits in say a 50 pixel strip on the left. So if you set the size of the menu panel by a multiplier, then the menu panel will become larger on bigger screens. This would somewhat nullify the advantage of having a bigger screen to draw.
This is when you use magic numbers as you know the menu panel needed to be no larger than 50 pixels.
(Note: never use magic numbers directly. Create constants like k_menu_bar_height = 50. Then use this constant wherever you need. This is much more readable and helps in the long run from a maintenance point of view)

Setting text size according to overall width of superview

Its not really a programming question but a design implementation question but anyway im wondering how you choose the text sizes in general according to the screen size. So an example is like before there was auto layout i used to say I want this views width to always be 30% of the superviews width. So no matter on what screen, be it iPhone or iPad, the width of the view will always be 30% of its superview. Now im wondering how would you choose the text size. Whats the rule of thumb for choosing the text size of a UILabel if its going to not look good on an iPhone but will look good on an iPad. What i would really want from everyone is for us to talk about rules of thumbs we use specifically when hitting my current situation. What do you do?
Ok, first of all you should
read the HIG:
Now to add some value with interpretation, there's not inherently a different between iPad and iPhone. IF it's legible on device it should be more or less legible on another, unless you're on the cusp of being legible on the lowest DPI device - a poor decision in any case.
I cannot stress enough you should support and query the system accessibility fonts. I.e. people hard of reading will choose bigger fonts sizes, all of Apple's software and system supports it.
Usually in the iPad, you add more content/spaces but offer the same sizes. Buttons, as a rule can be bit bigger. That will define what looks good, widen margins on the iPad a bit, which I believe is already done.

iOS: Scaling for different screen sizes with Auto Layout

I am programming an app for iPhone and I am using Auto Layout. I understand how #1x, #2x and #3x works, but what I don't understand is how to handle different screen sizes with Auto Layout.
If I want a scene to look good both on iPhone 6+, iPhone 6 and iPhone 5, I need to take into account the very different sizes of each phone. I can't use the same image size (in points) on all iPhones, because it will look too big on smaller phones, or too small on bigger phones. And I don't even want to imagine the hassle of iPad layout.
How can I solve this? Should I use constraints to make all of my images scale dynamically? This sounds doable, but I'm wondering what the best solution is.
Thank you. I'm really at a loss here.
If you want to keep the propotion on different sizes (for instance an image that has the same apparent size in each device) you can use constraints.
One small trick that I usually do is:
Define an aspect ratio constraint (cmd + click beginning in your view and ending in your view):
And then force your view to increase in width or in height (ie: defining constraints for the left and the right).
It all depends on what you want actually, and the constraints/code will vary in different situations.
you could make the #2x and #3x unproportionally bigger than its #1x counter part, then use the UIImageView's intrinsic size to let it become bigger for the different screen sizes
never tried something like this myself but i dont see a reason why it wouldnt work

Auto adjust alignment to screen size

I am working on a BlackBerry App that has a lot of ImageButtons, LabelFields and MessageBoxes. What appears to be perfect on one screen size, seems a mess on the other. For instance, Vertical Field Managers that are neatly aligned center with LabelFields, are left/right aligned on bigger screens. Images that cover the width of the screen appear too small on larger screens. Is there some mechanism to auto-align and dynamically change images with respect to the screen size. Any ideas and documents that can help in this regard?
Here are some tips for making screens that look good on almost all devices:
Use less images. If you have to use images, use atleast 3-4 for different screen sizes. for example if you need to have an image as the screen header, use images with widths 320px, 480px and 640px. Load image depending on the width of the screen.
Do not use pixel measurements. Use point measurements instead. Most of the devices are similar in terms of physical size, whereas they have huge difference in pixel density. Using this you can have a screen which will look exactly identical on curve (320x240), bold2 (480x360) and bold 4 (640x480). If you notice, they have the same aspect ratio and similar physical size.
Do not hardcode positions. Instead use FIELD_HCENTER and DRAW_HCENTER etc for fields.
Do not use fonts with fixed pixel height. Use fixed point height instead.
If using custom fields, make sure that they can automatically expand according to device and pixel density.

Resources