Content view height not increasing based on UIScrollView - ios

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.

Related

Autolayout constraint conditional

I have a view and I add a subview to this with the following Autolayout requirements:
If view width is greater than or equal to view height, then i want subview width to be 75% of view width and height to be 15 points,
If view width is less than view height, then I want subview width to be fixed 15 points and subview height to be equal to 75% of view height.
How do I express these constraints programatically.

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

How to constrain view's width to device width in interface builder?

I have this view hierarchy
I want my content to grow vertically in content view but not horizontally. so I want to constrain ContentView's width to be the same as device's width. How can I do this in Interface Builder?
Note: The image's width in Image View is bigger than device's width, so right now ContentView's size grows both vertically and horizontally
just add the constraints to content view as leading space,trailing space,top space,bottom Space along with fix content view width constraint as constant and then create the outlet for width constraint value and in view controller side write method as
-(void)viewDidLayoutSubViews
{
_scrollViewContentViewWidthConstraint.constant = self.view.frame.size.width;
}

how to set scrollview content size with auto layout?

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.

Resources