Bottom Constraint with UIScrollView - ios

Im trying to make a dynamic UIScrollView, using this answer I could make it work Calculating contentSize for UIScrollView when using Auto Layout
These are my label constraints:
The scroll is working, but since I have the bottom constraint the view will always have the huge space in the bottom. But if I remove the bottom constraint the scroll will not work. How can I keep the constraint but at the same time don't have all this huge space? Is this possible?

The solution was to make the view inside the scroll view to have the same height as the label so i don't have that huge bottom constrain, doing that solved my problem since the new bottom constrain is now 8 instead of 595.

To get the same size and location of the picture, I suggest to
delete the "595" Bottom Space constraint and instead set a height constraint on the UILabel. This will get rid of all that huge space.

Related

UIScrollView with multiple multi-line labels and AutoLayout?

Is there a way to achieve this? I have tried literally everything and nothing has worked for me yet.
So basically what i want to do is the following: I have a scroll view with some labels in it. All the labels get their text from a server and I have set their number of lines to 0 so that they change their height according to the amount of text. However, this does not affect the scrollview content size(even though my labels have constraints set up to the bottom,top,leading and trailing of the scrollview) and the labels go off screen and I am unable to scroll down. Can someone point me in the right direction to how I would set up my constraints, my view hierarchy and etc?
Any help is much appreciated! :)
Late, but this solved it for me:
Set leading (I have a 32pt inset), trailing and top constraints. The trailing will not actually seemingly do anything..
Make the trailing Greater Than or Equal to avoid localization alert.
Finally, add a new Equal Width constraint to the label matching the scrollview. Use the constant to subtract the required padding (I used 64 due to mirror my leading inset).
And voilĂ ! The Label will align correctly both in IB and in-app.
In Scrollview the last view's bottom constraint is so important. You should set its priority to 250 and put it to Greater than or equal.
Remember you should only change the bottom constraint of the last view, which in my case it's the continue button.
I would consider using UITableView instead, it has several benefits:
It allows for reuse of cells, if all the cells look the same
It manages recycling of cells when the number of values you're getting from the server increases (decreases memory pressure when number of cells becomes substantial)
It allows for more flexibility with the content (it's quite often for design to change last second or to evolve over the course of the project)
Most importantly, UITableView support auto sizing cells (as of iOS8), you need to specify the constraints between the label and the borders of the cell
There are several resources to start with:
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout
https://www.captechconsulting.com/blogs/ios-8-tutorial-series-auto-sizing-table-cells
http://www.appcoda.com/self-sizing-cells/
Use a container view in a scrollView
Add constraints to superview (leading, trailing, top, bottom, height,width)
Make IBOutlet of constraints that you are going to update.
Add you all labels inside that view.
Update constrains/frame of your label so that it fits the text.
How much you increase the label height you should increase the container height too.
If the label count is not fixed use custom label class to add subview.
Perhaps you should need to understand how ScrollView works in Storyboard with autolayout.

UIScrollView's Content View is ignoring equal width constraint to main view on Xcode 6

I've added a Scroll View that contains a content view. The scrollview's constraints keep it just below my progress bar and attached to the leading, trailing, and bottom of the superview. The content view's constraints hold it to the sides of the scroll view, with one additional constraint: equal the width of the superview.
Everything looks great on the storyboard preview, but at runtime the scrollview's calculated width increases.
Basically, it seems that AutoLayout is ignoring my constraint to constrain the width of the content view, and instead just allows the content view to get as large as it wants to fit the content in.
Here are my constraints:
Thank you so much for helping me get over this roadblock! I've been banging my head against the wall for days.
Here are some things I would try. I don't have comment privileges yet, otherwise I would ask for elaborations:
Are there any outputs in the console for Xcode? Generally when Autolayout is forced to break constraints, it tells you about it in the logs.
So to be clear, for the Content View, you have a constraint that sets the width equal to the ScrollView, as well as constraints to match the Leading and Trailing edges to the ScrollView?
If the constraint is not being followed then either the ScrollView is also expanding somehow, or the constraint conflicts with another constraint, and the width-matching constraint got broken somewhere along the way.

Keep UILabel centered using Auto Layout

I'm trying to keep my UILabel centered horizontally. I have tried in IB setting leading and trailing, but that simply stretches out the entire label, and I need it to stay the same size. Everything is set up using Editor and the Pin function in IB and not coding. Suggestions?
If you want to keep all the time buttons together and aligned to the center. Put them all in their own view, arrange how you wish. Then fix the length and width of the view and center it in the container like Aaron suggested. I do believe you will need to make one more constraint. Perhaps pin the view to the top. Hope this helps.
Seems too obvious, but did you try nsconstraint of width = XXX. Label should say same width and the leading trailing should keep it put.
For keeping a UILabel horizontally centre, add the following constraints:-
Width constraint to the label.
Height constraint to the label.
Top/Bottom Constraint for placing the label vertically.
Horizontal centre in container.

Aling UIView to a UIToolbar using autolayout

I trying to align an UIView to the bottom of a container view(UIScroolView) and above a tool bar.
It works perfectly when design to the iphone 3.5 display but when a change my layout to the 4.0 display, my view doesn't get alined to the bottom instead it stays in the same position with a gap from the UIToolbar.
I checked and i realized the i have a constraint Vertical Space with a constant and i think thats why my view always stays in the same place, the problem is i can't get rid of this constraint, i'd like to know if someone could help me with this one.
thanks!
I think you need to add a height constraint to the toolbar. If you have that and a zero length vertical spacing constraint between the toolbar and scroll view, you should be able to delete that constraint to the top of the super view.

iOS 6 Autolayout not resizing properly

So all I'm trying to do is put an imageview at the foot of the screen. Before iOS6 autolayout I could just hit the bottom "I" and it would hold it to the bottom and push it up if the screen got short (i.e. if the screen size went from 568 to 480 points tall). But now I have been trying to add a bottom spacing to Superview at 0 but I can't seem to do anything to get rid of the the top spacing constraint to stop messing me up. If I convert the top spacing to a user constraint and then delete it then (thinking that the vertical constraint would be handled by the bottom spacing) but it auto re-creates that contraint... any ideas?
Update It seems it was due to the fact that I was having it be a subview of a scrollview (was going to use it for scrolling horizontally, not vertically). Anyone know why it wont let me do that? Seems like you should still be able to constraint to the bottom of a scroll view.
It could be that the Button's constraints are somehow wrong. Having the height, width, bottom distance and horizontal centering should be enough to define its position. Try deleting the button and centering the image view on the super view instead, and see if tha allows you to delete that top constraint.

Resources