Height of UIViews proportional to height of Screen (Auto Layout) - ios

I would like to make the height of the UITextFields and one UIButton I have into my view proportional when the height of the screen changes. The default height of the textfields and uibutton is 55, but I realised that in iPhone 4, this height doesn't fit propertly the screen.
How would you approach this thing with Auto Layout?
iPhone 4.7 inch
iPhone 4.5 inch
Thanks!

I'm definitely not sure changing the height of textfields is the right approach to addressing your layout issues, but if you actually want to do so, it's as simple as creating an "Equal Height" constraint between your textfield and the view, and changing the multiplier so you get the value you want.

Related

Is it possible to set width and height for different iPhone screens?

I'm working with my project on the storyboard and I have a problem with screen sizes. It looks simple to solve but not for me. I have an imageView, and its width and height are looking good for iPhone 7/7+ screens. But It is not looking good for 5 or SE Screens.
Can I set different width and height for 5 screens? for example, while 7 and 7 pluses run with 200 width and height, iPhone 5 screens will run with 100 width and height. Or is it possible to squeeze the imageView? When I set the constraints imageView it also needs width and height for looking well, but it prevents to squeeze the imageView as well.
If you want the imageView to squeeze, you shouldn't give it a static width or height in the constraits.
One way to go is to set the leading, trailing, top and bottom constraints for it ==> no need for a width or height constraints.
Another way is to give it a proportional width and height, and this can be done by giving the image view an equal width and equal height constraints to its parent view for example, and then set the multipliers of these constraints to some number, 0.5 for example, this way the image view will always take half of the parent view's width and half of its height.

Autolayout a view within a view

I'm trying to have auto layout for my ios application but for iphone 6s the border is too small I've tried using pin and alignment constraints but it doesnt look right. The iphone 6s plus looks fine though. The only problem I have is the iphone 6s. The third image is what I have right now which is the view has is horizontal and vertical in container.
It looks like you're using fixed dimensions for the cells and the inter-cell spacing. Using a UICollectionView is probably overkill for this example, because you'll always have 9 squares for Tic-Tac-Toe. If that's the case, then you can do the following, assuming that the squares are UIButtons and they're contained in a plain UIView:
Constrain one cell's height and width to be 1/3rd the view's height and width. You can do this in the storyboard by adding height and width constraints that are equal to the superview's, but with a multiplier of 0.33.
Constrain all other cells' heights and widths to be equal to cell #1's.
For the borders, use User Defined Runtime Attributes to add a border, like this:

Button size varies in iphone 4 and iphone 6

I have one project where there is one button.
Which seems so big in iphone 4 as per the size in iphone 4 resolution
and same button looks small in iphone6 as per the size of the iphone 6 resolution.
I had used autolayout.
But is there any solution to manage it by autolayout or constraint.
Instead of managing size i.e hieght and width programmatically ?
Give that button an equal width constraint with its super view.
Select that equal width constraint and give multiplier value as (width of button)/(width of superview)
then give aspect ratio to the button.
Now the width of button varies with the width of device and height will change in proportion with its width.
I use this method and it works good.
If you want to manage size of your button, with the ratio of iPhone/iPad screen,
First you need to set equal width and height constraint to your button in storyboard.
Then in code, you have to add two IBOutlet of NSLayoutConstraint and connect them to respective constraint in storyboard, then update yourButtonWidthConstrant.constant and yourButtonHeightConstrant.constant from code according to the ratio.

Get variable height for a UIButton for iPhones 5/6/6+

For my 1) portrait only 2) deployment target iOS7/iOS8 app, I have in my design UIButtons which have variable heights, for iPhone 5, iPhone 6 and iPhone 6+. I am trying to use auto layout for this. (Not using size classes though).
Using auto layout how can I specify variable height for UIButton for these 3 screen sizes. The buttons look fine on iPhones 5* models, but thinner on iphone 6/6+. Now in auto layout I can say height >= or = or <= say 55), but how do I specify 44 for iphone5, 55 for iphone6, 66 for iphone6+?
Is this something that I can achieve using only auto layout or do I need to manupulate (frames) it in code? What is the point of me using auto layout then?
In addition to frames my designs also specify different font sizes. How do I go about this. Any best known methods for this, Stack-O friends .. ??
You are correct to ask "what is the point of auto-layout if I have to manipulate frames directly"? Thankfully, you don't have to.
An easy way of doing it is specifying the height in relation to a view of standard height (think a view that fits the whole screen).
For example, we can set our button's height to equal half the height of the view.
This way, the button is always going to scale with the view, either upwards or downwards (size-wise). Auto-layout will guarantee that the relation between them will always be 1/2.
Now the button will be half the size of its superview, regardless of size.
It sounds like you need to be modifying the height constraints constant value.
In your xib/storyboard, create an outlet to your view/controller for the height constraint.
At runtime, probably in viewDidLoad, you will work out which device you're on, and then just change the constant of the height constraint.
CGFloat height;
// if iPhone 5
// height = 44
// else..........
self.buttonHeightConstraint.constant = height;
This will automatically trigger a flag that tells AutoLayout to recalculate frames and layout the view again.
I managed this by adding a Height-Constraint to the UIButton. Make an Outlet and you can set the Height in your UIViewController subclass with _myConstraint.constant = 55;

Auto -Layout UIView for both Retina and non-retina views

I try to put UIView at to bottom of my UI. When i put everything seems to fine , except when i check it with Retina Form Factor the UIView sticked in bottom but height is increased than normal layout:
How can i set UIView with auto-layout for both retina 4 and non retina Screen Size. Also UITextField and other UI Objects have no problem with that issue.
You need to set up your Auto-Layout constraints in a way that accommodates both screen sizes.
In the case of the view you're showing here, adding a height constraint in interface builder to the view should take care of that problem.
Adding a height constraint will make sure that whatever screen size is being used, that view will remain at a constant height.

Resources