AutoLayout fill width of UIViewController - ios

I'm trying to get a UIView to fill the width of my UIViewController I've set the constraints as follows
and I'm getting a layout as follows in IB
What am I supposed to be setting to remove the margins on the view? I have a scrollview which I'm happen to have the margins on.

I also use left margin and equal width constraints but that could be taste. The other way would be to use a trailing constraint.
You can remove the margin in your constraint options. Otherwise you have to set it to -16 or something like that

It show that you have given constraints with margin. To avoid constraint with margin you can uncheck checkbox...

Related

Sometime there is an extra spacing(margin) in Xcode 8 (auto layout), why?

I put a view and set its trailing to superview with 0 spacing, but there is an extra spacing. I Don't know why this occurs, I clear constraints and add new constraints but space remains. Is there a bug, or I miss something?
It's because of the the Constraint to margins. Layout margins represent padding around the interior of a UIView that the layout system can use when laying out subviews - to ensure that a gap is left between the edge of a view and a subview.
You can avoid this by uncheck Constraint to margins while adding constraints.

AutoLayout in iOS using storyboard only

I have a ImageView whose top constraint is 80 and center. I have two textView with margin of 100 from top consecutive object and 100 margin from both left and right.
When I am trying to implement auto-layout i am not able to do so because of many warning as shown in the figure :-
your imageview and textviews are not comfortable with your current constraints .if you add top and centre constraints for uiimageview you must add the height and width constraints for accessing the x value.
and also you just add height constraints for both of your textviews and try again. thankyou
Every time when you give constraint do following things :-
Fix the width and height of the element.
Give one vertical constraint and one horizontal constraint.
Don't do over-constraint.
Update it where it is showing warning.
If you set Left/Right margin and CenterX, your system is over-constraint.
You should set : Left + Center or Right+Center or Left+Right.
Next you should change the content Hugging and Compression priority.

Change size of uiview with auto layout and make it always in centered

I have uiview with constraints for vertical centring inside superview and for width and height. On rotation of device uiview should always be in center, but I need to have ability to change width of uiview but its position should not be changed. I have tried:
- to add leading and trailing constraints but in such case width of uiview is no changing at all
- to add constraints for width that it should be greater and less but in such case width is not changed, uiview just moved
If I am understanding the issue correctly, you probably assigned too many constraints on the view so the autolayout system has a conflict and removes some of the constraints and then the ones you want there don't have any effect. I suggest you look into debug output window to see warnings about constraint conflicts and which ones are being removed.
What you want is: remove all the constraints you added on this view, then constraint its leading to the left side of the super view, constraint it to horizontal center inside superview. This way the uiview will be centered, and will resize accordingly. You can also constraint height or constraint the aspect ratio between width and height. What you definitely don't want is to constraint the height and width directly.

Equal widths / heights with parent (root) view?

I'm trying to add constraint in Storyboard to an UIImageView to it's superview, equal widths or heights but it's disabled.
I tried selecting both the view and the superview, then the add constraints button at the bottom right (mentioned constraints appear disabled), I tried dragging from view to the superview (mentioned constraints aren't listed).
I tried removing all the constrants related to my view. Didn't make a difference.
I'm using a xib, of a custom view. The parent view is also the root view. XCode 6.2 beta. Using size class Any/Any.
Any idea? Thanks.
For making UIView height/Width equals to super View.
Here's what you need to do.
You can set leading,top,tailing and bottom constraint by right clicking to View and select superview.
After setting Top and bottom constraints as i've set in previous image. You need to update constraints to '0' as it might have top and leading space not equal to '0'. You can select those constraints and changes constant to '0'.
You can also set constraints from pin to View as i've set for leading and tailing you can also set top and bottom option in similar way.
EDIT:
If you want to set width and height equally then you need to select both the view and set it's equal height and equal width. As I've set them in below image.
Result:
Below two images shows how you can changes width/ height using multiplier as you need to set constant to 0.9. as from storyboard or xib you cannot set constant in float. So you need to set multiplier.
First Image I've set multiplier in ratio.
Second Image I've set multiplier to 0.9
If you still face any queries please let me know. Hope this will help you solve your problem.
Don't give the inner view (UIImageview) any width or height
Add top margin (with superview) with 0
Add bottom margin (with superview) with 0
Add left margin (with superview) with -16
Add right margin (with superview) with -16
Well, I ended adding a parent view in between. This parent is constained to the top view - left, right, top, bottom: 0, and then I can set my inner view to equals width and hight to the parent (the reason I want to do that is to make proportional size - set constant to e.g. 0.9).
No idea why it's not possible to do this directly with the root view.

Applying autoLayout constraints to multiple objects

I am playing with autoLayout constraints in iOS
My use case is this way,
I will better explain with images
I am using a custom cell for UITableViewCell, through autolayout I have set constraints for text and divider line below and they obey autolayout constraints. Now you can see the yellow vertical strip on the left.
I have not set any constraints for it, so when the cell height is normal, it covers the whole cell, but when cell height increases, it doesnt increase and fill the whole cell. I am not able to make its height flexible w.r.t to cell.
I want to expand the yellow strip to cover the whole cell.
So how I can achieve this.
You can make height of yellow strip flexible by setting 2 constraints.
Set both top space and bottom space to container (cell's content view) to 0.
Ensure there is no constant height constraint for it.
You need to set constraints to the yellow view. By default it would apply its own constraints at runtime.
To the yellow view add TOP , BOTTOM , LEADING , and TRAILING constraint. DO NOT ADD A HEIGHT constraint.
Make sure the TOP and BOTTOM constraints of the yellow view are pinned to the cell's content view.
Let me know if it works.
Cheers

Resources