How to Configure AutoLayout for UIView - ios

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?

Related

How to make the screen adapt when you use a freeform simulated size in Xcode?

I am making an app and I have a UIScroll view in my viewController. I have set the simulated size to freeform and the height to 2000 and width to 375. When I run my app on the Iphone 7 There are no problems. But when I try to run the app on the iphone 7plus the screen does not adapt and i get these white bars on the right side because my contents width is only 375 pixels. So how can I make my screen to automatically go bigger when I use a bigger device?
If not already done, you should add contraints (trailing, leading, top space, bottom space) to your UIScrollView to pin it to the superview bounds.

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:

stuck in concept of auto layout in Xcode 6.4

I just started to learn auto layout.
I have switched off the Use Size Classes.
I make there UILabels which is shown in the image and their constraints also. I want to look similar in 4s,5s,6 and 6Plus.
But it is working fine on 4s and 5s but distorts in 6 and 6Plus.
Why this is happening and how can I resolve this.
My StoryBoard with constraints:
Output iN 5s
Output IN 6 and 6Plus
Assuming that the way labels are placed in 5s is what you are really looking for, place the constraints as follows :
Pin width of all labels equally.
Pin Height of all labels
Pin vertical position of all labels from top margin equally.
Now, as for the problem, add the constraints as follows for horizontal placement of labels :
[leading margin--0--label1--40--label2--<=20--label3--Trailing margin]
Adding the horizontal constraints should work for all sizes.
This happens because none of your constraints is hooked to the leading/trailing layout guide. What you'll want to do is to attach labels 1 & 3 to the "sides" of the view, and then attaching label 2's constraints accordingly. (I would recommend adding a center horizontally constraint, but it can be achieved by different ways).

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.

How can I stop Auto Layout from stretching the height of my popover when on an iPhone 5?

On an iPhone 4 (or any iPhone/iPod device without the 16:9 iPhone 5 resolution) my popover looks great; not stretched at all and exactly as I intended.
However, on an iPhone 5 the popover is stretched:
And I can only assume it's because of a constraint with Auto Layout, but I can't quite figure out what is causing it.
When I select the UIView that contains all the controls in the window (and what appears to be being stretched) in Interface Builder these are the constraints it has on it (again, apologies for the height of the image, it has a lot of subviews):
I thought it was Top Space to: Superview Equals: 103 but I cannot delete that. I promote it to a user constraint, then delete it and it just reappears.
What am I doing wrong here?
In Xcode you can't delete a constraint unless there is enough constraints remaining in order for Xcode to determine the layout in Storyboard or IB, usually at minimum 2 constraint vertically/horizontally. So you will need to add a height constraint (2nd from the top) first before deleting the top space constraint:
This will give you a fixed height constraint that you want in the first place.

Resources