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

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.

Related

Rescale UIImageView proprtionally in Launch Screen Storyboard

I have a UIImageView that needs to be centered and have a width that's equal to the screen width and some height that grows proportionally with the width. So for instance, for the iPhoneXR I have:
And on the iPad 9.7 it would be:
So basically the image just scales proportionally with each screen size. I have already figured out how to center it using constraints, but I'm lost on how to get it to scale proportionally. I've played around with the auto resizing options and constraints to no avail. I struggle so badly with these storyboards, wish I could just code it! Is this even possible in a LaunchScreen storyboard?
You can't execute any code inside launch screen. However, you can make it with constraints.
Set center equal to superview, then set width equal to superview. Now, you can add aspectRatio which is like 1:1, so you imageView height would always be equal to its width or any other ratio you want.
Example:
By adding proper constraint you will get your expected result. Add aspectRatio constraint to imageView.
All constraints as per
You can not give constraints to a view w.r.t viewController in LaunchScreen.storyboard because our view hierarchy has not loaded till that point of time.
You can give an imageView constraints w.r.t itself. CTRL drag on the imageView and select height, width or aspect ratio.
Though the recommended way will be to use another viewController that will work as LaunchScreen with some delay in segue.

myView.bounds.size return's same value for all screen sizes

I have a subView called contentView which almost flush with the superView.
I designed the subView in Storyboard with iPhoneX and added the necessary constraints to stretch for all screen sizes.
On the different screen sizes the view appears to be stretched as defined by the the constraints but the bound.size of the view remains same on all screen size
contentView.bounds.width
the above on all screen sizes prints the following value
375.0
I am adding more subViews to my contentView according to it's width, but on all screen sizes I get the same value.
It seems that 375 is the width in points for iPhoneX on which I originally added the contentView.
Is there any reason for this as Googling for this problem didn't help.
I would really appreciate if any one points me in the right direction.
Here are my constraints
If you expect constraints to be applied in viewDidLoad(), well it's too early. Views are only assumed to be constraint-ready in viewDidLayoutSubviews().
Add
self.view.layoutIfNeeded()
print(“\(myCustomView.bounds)”)
Then you can print the correct bounds.
This forces the view to update all sub views to the the constrained sizes before you check it. In viewDidLoad that is still going on so this makes sure that has happened.
You can do this in viewDidLayoutSubviews() as well but if the view is a subview of a subview it may not be correct even in that function.

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

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.

UIButton inside UIScrollview not resizing with UIScrollView even after adding the constraints

I am facing a weird issue. I have implemented custom UIButtons as a Tile View in a UIScrollView which is added to superview. It is like there are six buttons, set of two placed sideways, and next set of 2 below them and so on. Now for implementing it to fit all iPhones Screen Sizes, I have added proper constraints to UIScrollView and constraints to UIButton relative to each other and UIScrollView. I have added #2x background images to each of the button with resolution as 320 *320. I have not provided any heights and widths constraints to them, so that they stretch freely according to different screen sizes.
xib has been initially designed as a 4" screen size. UIScrollView frame is stretching, however button remain positioned as in an iPhone 5S xib, hence it is looking improper on screens like iphone 6 etc.
What is the exact problem here?
See the work done here and confirm if this is correct. I have added constraints required to make the buttons looks proper in all devices.
here is the link
https://github.com/mahesh-agrawal/Test-Buttons-Inside-ScrollView

How to Configure AutoLayout for UIView

I have a UIView in my iOS app that holds a graph. I have fully constrained the UIView in Interface Builder but yet when I view the page on my iPhone 6 the graph is a nice large size but yet when viewed on an iPhone 4s, the view appears much shorter to the point where it's uncomfortable to look at.
The constraints are as follows:
As viewed on an iPhone 4s:
As viewed on an iPhone 6:
How can I adjust the constraints so that the iPhone 4s UIView has similar proportions to that of the iPhone 6?
There might be some conflict in the constraints in 4S.
For this UIView, if the superview is fixed in terms of size, then only 2 of the following constraints need to be set.
align top to superview
align bottom to superview
height equals 150
Or if the superview is not fixed in size, then the superview constraints might have conflict with the tableview down below. try to set the tableview height using percentage, not the fix number?

Resources