Multiple UIVIew Autolayout issue - uiview

I have an UIViewController with four subviews its look like below picture first subview is 50% of the screen and remaining three subviews occupy the remaining 50% of the view.In the bottom first 25% its will occupy the 2:1 ratio range.remains are occupy by 25% of the view.it's will be positioning the ipad landscape view properly but in portrait view first view more than 70% occupy. how to resolve this

I've created the setup according to what you want. Please check the below screenshots.
Here are the steps to create this setup:
1. Add the four views into the main view.
2. Add leading, top and trailing space constraints from the brown view to the main view.
3. Add vertical spacing and leading constraints from the purple view to the brown view.
4. Add vertical spacing, trailing and equal heights constraints from the green view to the brown view.
5. Add bottom space constraint from the green view to the main view.
6. Add horizontal spacing and equal widths constraints from the purple view to the green view.
7. Add vertical spacing, leading, trailing and equal heights constraint from the orange view to the purple view. Change the multiplier value of this equal heights constraint from 1 to 0.5 in the size inspector (See the last screenshot).
8. Add bottom constraint from the orange view to the green view.
1. Views in Storyboard:
2. View Hierarchy and Constraints:
3. iPad Screenshot in Portrait:
4. iPad Screenshot in Landscape:
5. Size Inspector:

Related

Storyboard Constraint Issues: Half the height of the screen

I have a 4 labels in a storyboard, one large one at the top, and 3 smaller ones, with the bottom one centered in the middle(horizontally and vertically) like so:
I have a few constraints set already, like locking the top label at the top of the screen, and centering the bottom. However, I do not know constraints I should use so that all four labels are equally spaced, AND the bottom label remains at the center. I have played around with some constraints such as the spacing between the labels, but when I try to view this using a different screen size, everything is messed up:
Any ideas?
The best approach is a UIStackView with axis-> vertical , distribution -> fillEqually , so hook it's top ,leading , trailing to main view , drag the 4 labels inside it , and ctrl drag from the bottom most label to main view and select center vertically && horizontally
You can made a trick here:
Set the top global label top constriants and center horizontally to super view.
Set the bottom label constraints center vertical and horizontally to super view.
Take three dummy view between label one-two, two-three, three-four.
Set constraints between these dummy view as equal height.
Then set top-bottom contraints between label and dummy view properly.
Set horizontal constraints of the label and dummy view. I have set as center horizontally.
Here I have attached the image:
For better understanding I have colored the dummy view as light-gray. You can set it as clear.

How to make grow UIViews proportionally

I have view simmilar to this below:
Views stack
How can I make it possible to make height of first and last view bigger proportionally, when making yellow view height smaller? Can I do it by setting content hugging priority and content compression?
Now that I apparently understand your problem, I suggest the following:
The top of the violet view has to be set equal to the top of the superview.
The height of the violet view is still undefined.
The bottom of you violet view has to be set equal to the top of the label.
The label has a fixed height.
The bottom of the label has to be equal to the top of the yellow view.
The yellow view has initially a fixed height.
The bottom of the yellow view has to be set equal to the top of the button.
The height of the button is still undefined.
The bottom of the button has to be set equal to the bottom of the superview.
This leaves the heights of the violet view and the button undefined. But your requirement is that their heights are proportional.
This can be achieved be setting them first to be equal to each other. Then double click the constrains and change the multipliers, e.g. make the multiplier of the violet view larger, and the multiplier of the button smaller.
Then you have an unbroken chain of vertical constraints, and auto layout should work correctly if you assign a height of 0 to your yellow view.

why does my view embedded in UIScrollView scroll only a little?

In my UIViewController I put a UIScrollView and attached constraints:
Then I added a view to this scroll view with following constraints:
and positioned it like this:
so as you can see it is quite long. When I run the app I can scroll it just for couple pixels instead of completely to the top of the screen. I want to make it possible to scroll it to the top so that it can cover everything what's under it. So what am I doing wrong here?
========= EDIT
for clarification - I want to achieve an effect that when user opens this screen, 10% of the screen is covered by the view. User can slide up this view and then it covers 90% of the view. And he can slide it down back to the 10%. Can you help me with adjusting constraints so that it looks good on every screen size?
Take a UIView inside the UIScrollView.
Set the constraint for scroll view as leading, trailing, top, bottom.
Select UIViewController in the story board and click size inspector then choose freeform then set the view height as bigger.
Then set constraint of UIView is leading , trailing , top , bottom as 0, so that the UIView will be same as ScrollView region. Now set height constraint something bigger so that you can design image view, label 1 and label 2. Then set constraint like the image view : top to UIView, leading , trailing and height.
For label 1: leading, trailing , vertical to UIImageView, height.
For label 2: leading, trailing , vertical to label 1, height and bottom to UIView (Important as based on this content view will be set).
After setting constraint You can select UIViewControl from story board and set the SizeInspector as fixed as it was before.
It will show the screen as you need (Image view, below label 1 and on scrolling label 2)
I have tested it in my demo project.
Hope it helps

UIScrollView and Autolayout prevent contentview compression

In IB I have a view controller that contain a scrollview.
The red view is inside the scrollview
The minimum height of the red view is 504px, so on iphone 4 it should scroll and on iphone >=5 it should extend and layout the buttons to fill the blank.
I set the constraints of the red view to 0 from top, leading, trailing and bottom of the scrollview and also centered horizontally and vertically.
My redview has a minimum height of 504
The blue and green views have equal height
Everything is fine for iphone >=5 but for iphone 4 the red view is compressed to be the size of the scroll view and the buttons are touching each others.
After multiple constraints adjustments I'm wondering if it's even possible to do what I want 100% in IB with autolayout
You say (emphasis mine:)
"I set the constraints of the red view to 0 from top, leading, trailing and bottom of the scrollview and also centered horizontally and vertically. My redview has a minimum height of 504"
First, I can see some redundancy (the bold part).Your redView does not need the vertical constraint since you have already pinned it on the edges of the scrollview and has a defined minimum height.
But this could or not be the cause of the buttons coming closer together, depending on the rest of the constraints.
Have you set vertical space constraints for the buttons?

AutoLayout UITableViewCell

I am working with autoLayout for UITableViewCell
So here is my xib and constraints
Here I set constraints such that tableView has dynamic height
Whenever I run on iphone5, it looks this way correctly which I want
But when I run the same thing on ipad it shows this way
So I am not understanding how to make the ipad version look same as iphone version, Not understanding which constraints I am missing.
When working with autolayout constraints, formulate what you want into sentences.
Example:
I want the yellow view to be pinned to the right.
I want the yellow view to be pinned to the top and bottom.
I want the yellow view to have width of 50.
I want my label to be pinned at the top and bottom.
I want my label to be pinned to the left.
I want my label to be pinned to my yellow view, with 10 pixels between them. (Thus growing in width along with the superview width).
And there you have all your constraints. Now you just have to add them one by one. Top, Bottom, Right to superview and Width constraint with a constant of 50 for the yellow view. Top, Bottom, Left to superview and Right to Yellow view with constant of 10 constraints.
You've pinned your yellow view to the left of the superview, so on bigger screens, it will grow to fulfill that constraint.
It looks like you pinned the left edge of the yellow view to the left edge of the table view cell with a 300pt offset. That means on the iPad, the yellow view is still 300pts offset from the left edge of the screen, and grows to fill the rest of the width available.
What you probably want to do instead is pin the right edge of the yellow view to the right edge of the table view cell with a 0pt offset, then also pin the yellow view's width to its desired size.

Resources