UITableView And UICollectionView inside scrollView not visible - ios

I have a tableView and a collectionView inside scrollView. Both of them have constraints for left, right, top and bottom. But both views are now visible when inside scrollView
Why may it be ?

I think scrollViews Need to know width and height for its subViews

Follow these steps:
Disable scroll for table view and collection view.
Resize the height of table view and collection view as per its content (If Dynamic height)

Related

How to make auto resizing label inside scrollview?

I am using a view inside a scrollview and inside the view, there are two labels with fixed width. and I want to make these labels auto-resizing in respect of height. For this I have given the height of the view >= but it's breaking the constraints. How can I achieve auto resizing content within scrollview.
While using scrollview it's mandatory to give the height of the elements inside scrollview. But if we want to make an element self height adjusting then we can give the minimum height with the priority 250
First, you need a content view inside the scroll that has constraints with the controller's view (equally both width and height) and top, leading, trailing, bottom with scroll view.
Then, add any subviews inside that content view. In your case is the label's bound view.
Something like:
The red one is the content of your scroll view
The gray one is bound label view
Just embed all these labels in stack view. And that's it.

Can't scroll with collection view inside scroll view

I have the following structure:
- Scroll view
- UIView
- Collection view
I gave the UIView the following constraints:
top, left, right, and bottom = 0
Equal width and height to the Scroll view
I've also disabled scrolling for the Collection view, as I want the whole page to scroll together.
However, when items are added (dynamically) to the collection view and I try to scroll, nothing happens.
What am I doing wrong? How can I make sure that the page scrolls all together?
Maybe you should try removing the equal heights between view and scroll view because this limits view's height and doesn't allow collection view to grow.

UIView is not scrollable inside scrollview

I have view inside scrollview. Inside UIView there are many objects. I want that view should be scrollable.
I think UIView is not suitable for this kind of situation, because there are many objects aligned vertically, so i prefer to use stack view. Now scroll is working!
You need to understand first how UIScrollView works. There should be a warning message that says like this:
ScrollView has ambiguous scrollable content
Your scrollView won't scroll because it means that the subviews of your scrollView does not have enough constraints attached to them and to the scrollView to make the scrollView scroll. Well how does the scrollView scroll? If the content of the scrollView exceeds the frame (either width or height) of the scrollView, then the scrollView will be scrollable.
Adding height of contentview(view) inside scrollview will make the scrollview scroll with other necessary constraints
Better You can Increase the view controller's Height and add a scroll view with it
I hope this video helps.
How To Create A Scroll View In Xcode 8 (Swift 3.0)

UIScrollView not scrollable vertically with storyboard(using autolayout)?

I just add a scroll view to the storyboard, and added two views on the top and bottom, and making the bottom some part outside of the view to make it scrollable, but it doesn't work, what I have done wrong?
Inside you scrollview add a view with fixed height constrains and inside that view you can add your subview according to your design.
You can also set content size of the scrollview from storyboard.
If you are not using AutoLayout, then try to set scrollview.contentSize = bottomview.frame.origin.y+bottomview.frame.size.height This will make scrollview scrollable when device screen height is less than bottomViews bottom edge. In this make sure that your bottomview us immediate subview of scrollview.
For scroll in scrollview you need to give inner bound to scrollview with subview.
See image vertical scrolling with auto layout
Your problem may be you not give top and bottom inner bound to scrollview.
Like you added 2 view then for top view give top constraint and for bottom view give bottom constraints to scroll view.
Now you subviews height must be more then scrollview's height.
Scrollview need inter bounds (scrollview to it's subview) to scroll for vertical (top and bottom) and for horizontal (left and right).

How do I add UIView on UIScrollView

I wanted to add some labels and textfields on my view and that view should scroll, so I am thinking of putting view on scrollview.
I wanted to add some labels and textfields on my view
And that view should scroll
So I am thinking of putting scrollView
And then I wanted to put my view having labels and Textfields
Is it possible?
Please check scrollview property Bounces Vertically is checked or not if not check it
May be, your content is less, than ScrollView, that's why scrolling is disabled
Put view with labels in scrollview. Scrollview should be less in height than view. View should have height considering all ui cvontrols in it. should work like this
Make sure your scroll view height is not greater than view its content size has to be greater as all people says. You get confused between content size and scroll view height.
Meas using nib suppose your scroll view height is 300 and when you use the code content size should be greater than 480 so it will be scroll-able on iPhone 4 size device who's height is 480
To make sure your constraints are well defined, first check these steps:
Make sure your base view is a UIView
Put into a UIScrollView and add constraints to the edges of UIView
Put into the scrollview a UIView and add constraints to the edges of the scrollview. I call this "content view".
You should assign a width to the content view. I usually set the width of the content view equal to the width of the scrollview.
Put your labels/views/images/whatever into the content view and use autolayout constraints to resize them automatically to fit the target screen.
Please consider that:
Your scrollview must always have a height, fixed or dynamic. In order to avoid errors with autolayout, consider that:
the last element on the bottom of the content view must always have a constraint to the bottom edge of the scrollview, or
the content view must have a fixed height
If the height of your content view is less than the height of the scrollview, the view will not scroll. You should add more views or more margin to the bottom constraint of the content view.

Resources