Stretch UIView in a ContentView of a ScrollView - ios

I have the following problem:
I have a Scrollview with Autolayout top,left,bottom,right is set on 0, in this ScrollView is a ContentView also set everything on 0. The ContentView contains a ImageView a Segmented Control and a UIView which is connected to 2 different UIViewController.
The UIView is set top 0 to the Segmented Control and to bottom 0 to the contentView.
My Problem is that the UIView in the ContentView is not streets to the bottom of the ContentView. How can i solved this Problem?
Picture 1:
Storyboard UIViewController with ScrollView
Picture 2:
View on an iPhone 6 Plus
Here there are the size inspector constraints pictures:
ScrollView
MainView of Controller
ContentView in ScrollView
UIView in ContentView

Seems like the problem is in scroll view bottom content inset. By default scroll view have automaticallyAdjustsScrollViewInsets property enabled, and if you insert scroll view as nearest view to tab bar (as I can see at screenshot), bottom inset will set as nonzero (this used for show content under transparent tab bar while scrolling). But for use this behavior properly, you should connect scroll view bottom to view (root view) bottom, not to bottomLayoutGuide. Second option - disable automaticallyAdjustsScrollViewInsets property and handle contentInset and scrollIndicatorInsets properties of scroll view manually (set them to UIEdgeInsetsZero if you don't want change your constraints).

Related

View not reaching the bottom of the device screen using Autoresize Subviews

I have a view controller that has a button at the top center, and a view underneath which will have the collectionview inside. I want this collectionview to scroll separately to the top view (so it scrolls underneath that top section).
This works fine but the view with the collectionview doesn't reach the bottom. You can see in the screenshot I gave the superview a red background - the collectionview doesn't reach to the bottom of the view. All the constraints are fine.
It works if I uncheck "Autoresize subviews" in the Interface Builder for the UIView inside the View Controller but this then makes all the cells and any navigation bars I add inside that view 1000px wide. Why is my view being shortened - and how can I get the best of both these scenarios? A View that hits the bottom of the screen and all the cells/navigation bars the width of the view?
Constraints for the view:
Constraints for the collectionview:
I did have a tab bar too, and the gap is the exact height of my tab bar.
Anyway I fixed this by putting:
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;
in viewDidLoad method.

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

Why does my UITableView need to be below UIButton in the scene outliner

I have an UIView with a UIButton and a UITableView. I constrained the UIButton (left, top, right, bottom) to (0,0,0,-) with a height of 50px. Below i constrained the UITableView (left, top, right, bottom) to (0,0,0,0) so that the screen would be filled with both views as such:
In this case the UIButton is above the UITableView in the scene outliner:
However whenever I reorder the view in the UIView so that the TableView is above the UIButton in the Scene Outliner it also moves my UITableViewCells but not my UITableView:
The constraints are the same and nothing is moved except for the layering in the scene outliner. Why do my UITableViewCells move down whenever i place my UITableView above my UIButton?
Interface Builder does that when "Adjust Scroll View Insets" in view controller attributes is checked.

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.

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