how to set scrollview content size with auto layout? - ios

I have one screen where I have added 1 scroll view on self view. Tab bar and navigation bar both are there and for iPhone 4 view height is 455.I have added more content on scroll view.the height of scroll view and self view is same.but when i am unable to set content size for scroll view.even i set too it is not working.Please help me.
Thanks

Here is how to set up the size of the contentView in Auto Layout:
Add a view to your scrollView. This should be the only top level view on your scrollView and it will serve as your contentView.
Constrain the left, top, right, and bottom edges of this contentView to the left, top, right, and bottom of the scrollView with offsets of 0.
To size the contentView, add width and height constraints to the contentView. If you want it to scroll, the width and height must be larger than the width and height of the scrollView itself. If you only want to scroll vertically, set the width of the contentView to be equal to the width of the scrollView.

Related

Content view height not increasing based on UIScrollView

I'm having a main view with UIScrollview it's child and than another view as scrollview's child. After setting the scroll view's content size it's child view's height isn't increasing.
This is the hierarchy
-MainView
--Scrollview
---ContentView
i've set the scrollview's constraint as top bottom left right to 0.
The content view's constraints are top bottom left right to 0 and equal width and height to main view.
But the content view's height isn't increasing.
The content view's constraints are top bottom left right to 0 and
equal width and height to main view.
"...and height to main view"
That's it. Your content view's height is set to equal to the screen. Let the subviews of your scrollView (or subViews of your contentView) increase the total content height so that your scrollView could scroll vertically.
Just remove the height constraint from child view. It will make width equal to main view's width and height equal to the height of content view of scroll view.

UIScrollView - how can UILabel push down content offscreen

How can I get a UILabel with a variable number of lines to push down the content in a UIScrollView?
I currently have a UIScrollView pinned to the superview, a container inside pinned to scrollview and equal height/width to main view, and this blue UIView (height 50), 2 UILabels and a UIImageView (height 200) inside the container.
In landscape I want the UIImageView (i.e. black box of height 200) to not be pinned to the bottom of the superview, but be offscreen and the scrollview content size to have been adjusted.
In portrait I want the labels to size to fit and the black box to respect the top constraint to the bottom label:
Tried more stuff and the following worked:
set both labels' vertical resistance to 1000
delete the "equal height" constraint on the container
So the solution to seems to be:
add a scrollview and pin all edges to vc's view
add container to scrollview, pin all edges to scrollview, equal width to vc's view (height varies based on bottom pinning to content), add all content to container

My scrollView does not wants to scroll

This is my setup:
I do not know what I am doing wrong. The image view is bigger than the size of the view and of the scroll view. The constrains are set al followed:
Scroll view: equal heights to View * 0,5, equal width to View, center Y and X to View.
View (inside Scroll view): pinned all zero's inside Scroll view, equal heights and width. I also tried instead of equal heights and widths to center X and Y inside Scroll view, but it won't scroll.
How can I let the Scroll view scroll? Thank you.
Add a leading, trailing and top constraint and equal height of UIScrollView to superview with 0.5 multiplier. Now to your contentView (the UIScrollView subview), add a leading, trailing , top and bottom constraint. Also add equal height and width to UIScrollView. Set the height to a priority of 250. Add constraints for UIImageView inside this contentView.
Since the contentView will have a fixed height of low priority equal to the UIScrollView height. This fixed height constraint will break once the UIImageView total height(based on the constraints you add) will get larger than the UIScrollView height and the content will become scrollable. So at the very least you will always have a view half the screen size and become scrollable once the content becomes too large vertically.
You need to give contentSize to scrollview.
ScrollView.contentSize = CGSize(width: 1000, height: 500)
Which constrains have you given to imageview?
set constraint of imageview:
Trailing ,leading,top,bottom - 0 and also give height constraint.

iOS Autolayout storyboard ScrollView - button bottom of the scrollview is unable to clickable

Using Storyboard, in UIViewController using UIScrollView, UIView as content view
Scrollview Constraints - top, bottom, left, right
UIView as contentview constraints - top, bottom, left, right, equal width height to ViewController's View.
I am using these constraints, can anyone please help me out why button is not calling?
The button is not clickable because it is below the frame of the content view. You need to remove all auto layout constraints from your content view (the UIView inside the scrollview).
Then you can add all the objects that you need to add to the content view and set the height of the content view according to the height of the content.
So lets say that you calculated a height of 1000 for the content of the objects in the scroll view. You would then need to set the frame of the content view like this:
contentView.frame = CGRectMake(0,0,scrollView.frame.size.width, 1000);
And don't forget to set the contentSize for the scrollview so that the scrollview knows how much room it needs to scroll.
Just now found the answer with removing any autolayout constraints, for content view we have to set constraints like below:
Top, bottom, left, right
Align CenterX - here we have to set the content view height then for that constraint we have to set constant as scrollview content size height

Scroll UITableView horizontally using auto layout in storyboard

I used storyboard with autolayout enable. I put a UIScrollView in storyboard. Then drag a UITableView over the scrollview. I set the table view's width bigger than the scroll view's width. I then set the constraints with the trailing space to scrollview with a negative number and storyboard fill all other constraints without error. The structure look like:
UIView
UIScrollView
UITableView
in code, I set the scroll view content size:
self.scrollView.contentSize = CGSizeMake(500, 400);
the size matches table view's size. But it doesn't work. The table view will not scroll horizontally. What I am doing wrong and how to make a UITableView scroll horizontally. I mean the whole table, not the each cell scroll horizontally. Thanks for your help.

Resources