scrollview has ambiguous scrollable content height & Width - ios

How Can i solve it. I try all type of constraints like top, bottom, left , right, horizontally, vertically, also equal height and width plz see the link below for image

Scroll views are special when you set constraints. Because they have an undefined content size you must set constraints for both its contents' sizes and edges. Setting only top, bottom, left, right is not enough, also set height and width.
Try this. Add a single UIView to an otherwise empty scroll view. Then tie the edges of the view to the scroll view. Finally set the height and width to fixed size.
Read more

Related

Why is there a big margin in my scrollview when it's all set to 0

I have scrollview with a stackview with all my contents. I set all my margins to 8px but for some reason, there is a big space to the right. Even if I change the margin to 0px.
Am I doing something wrong?
Is it maybe better to make a tableview and make a cell out of my stackview? Seems very unnecessary to do this. But I cant figure this out.
When you define constraints inside a scrollview, the content doesn’t bind to the scrollview but to the content insets (margins). With this you can install content that is wider than the scrollview and be able to scroll horizontally.
What that means is the content of your scrollview can’t deduce its width just by sticking constraints to the sides, you have to explicitly set a width constraint on a child view.
In your example, it will use the smallest width it can, which looks to be the width of your three checkboxes.
To fix that, add a width constraint to any child view, like your first text field, or better, on your text edit because it takes the whole width.
In addition to this, you should add a CenterHorizontally constraint on your text edit too and make your left constraint on "Equal or Greater" or else your content will be aligned to the left.
Here is the official documentation on ScrollView to see this in more detail.
The content inside the scrollView must be the width of the device. The scrollView will not adjust to that width by itself. First try to set "equal widths" constraint of the scroll view to the view controller. If that doesn't work, keep reading.
For this StoryBoard, what you must do is put a UIView inside the scrollView.
The scrollView must be equal widths and equal heights of the viewController. Then the UIView must be equal widths of the scrollView, and then set its top and bottom anchor to the top and bottom anchor of the scrollview.
Copy all your subviews into this UIView.

Fixed label in that position and equal width

When I was setting a label to equal width inside a scrollview, the label goes up to top instead of staying at the original position. When I remove the constraint, the label is back to position, but without the constraint, the label is not responsive to the screen size.
I already set the scroll view responsive to the view controller. I wished to know the idea of fixing the label position and change the size accordingly to screensize.
Give constrains to your label: left align, right align and Center vertically to superview (in your case ScrollView).
If you can give frame. it will also work else :
Add a top, leading and trailing constraint to the label.
Top constraint will be responsible for your issue of moving to top and left, right constraint will take care of your width of label.

How to set Horizontal text field in landscape mode with auto layout?

In my app i want to set text field width according screen size in landscape mode,using auto layout.it's working portrait perfectly in land scape mode not working.
Here is my Screen with auto layout,
In landscape mode showing like this,
Here is my Constraints Screen
this my View Controller
I suppose you must have some superview under this layout that has explicit width set.
How does it look like when you tweak simulated metrics like size and orientation in your storyboard?
Alse remember to double check the view hierarchy.
Check the size inspector, your contraints should be:
trailing space to superview, leading space to superview, and some top and bottom space. And don't set explicit width value
EDIT: As you can see, the view which is the superview for your textfields and actually whole layout, has the explicitly set width value. Delete this value and instead set both trailing and leading space. This would work
Constraints for scrollview - leading, trailing, top and bottom and equal width to superview.
Constraints for view inside scrollview - leading, trailing, top and bottom to scrollview and equal width to scrollview.
And the constraints given to textfields, buttons, etc. are correct. You just need to revise scrollview's and view's(inside scrollview) constraints.
Don't need to set Centre constrain. Just set top , Leading and Trialing . so, Autolayout Adjust size automatically. check below image ,
Check Output :-
EDIT :-
Here i have attached Demo with Scrollview . check it.
Constrain with scrollview
Output :-

UICollectionView is too wide. How can i make it the width of the device?

I created a new UICollectionView in the storyboard. My problem is that the cells try and fit a larger width than the width of the device, so the ones on the right get cut off. What's a good way to fix this?
you need to pinned all edges of your UICollectionview...check out here
By pinned all edges, you'll get equal height and width of screen
You need to add the proper constraints to your collection view. If you want it to be the width of the screen, then add 0 length spacing constraints to both edges of the controller's self.view (top and bottom as well if you want it full height).

UIScrollView in Storyboard not working with iOS 8 Size Classes and Autolayout

So I'm trying to create a UIScrollView only in storyboard that allows me to add scrolling labels for more than the height of the VC. Here's what I did:
Created UIScrollView that took up the size of the any width any height VC
Made constraints 0 for spacing to nearest neighbor on top, bottom, left, and right
Created a view that is a subView of the UIScrollView with the same width as the any width any height VC but height of 1500 (because I only want it to scroll vertically).
Set constraints to nearest neighbor as 0 for ONLY left, top, and right and set the height constraint as 1500.
I put a label at the top of the subView and at the bottom
When I run the app on an iPhone 6, does not scroll vertically as I want it to. Any ideas why this is not working? Thanks in advance.
To obtain the scroll you have to pin the sub view (the "content view") to the top, left, bottom and right of the scrollview.
In addition you have to give it (to the "content view") an explicit (=not related to the scroll view) height and width because these are used by the scrollview to calculate its content size.
In your case set the width equal to the VC main view width and the height to 1500.
When width or height are bigger than the scrollview size, it will scroll.
Scroll view constraints (pinned to main view)
Content view (pinned to scrollview + height 1500, width=mainview width) + label constraints (as an example: 20 20 from content view top left)
For an easier visualisation, I created a video on how to do that.
Video on how to create a vertical-only scrollview in iOS
Have you set the contentsize bigger than the screen itself? In your case, just bigger in height.
As Apple Documentation says:
"You must set the contentSize property to the size of the scrollable content. This specifies the size of the scrollable area."
The only solution is add constraints to the right and bottom of the bottom subview of scroll view's child view.
Also check if all the views from top to bottom have got proper constraints along with height.
For the scroll view ' s wrapper view add equal width and equal height constraint to its superview.

Resources