UIScrollView Scrollable Content Size Ambiguity
Updated
Nowadays, Apple realized the problem we solved many years ago (lol_face) and provides Content Layout Guide and Frame Layout Guide as part of the UIScrollView
. Therefore you need to go through the following steps:
Same as above;
For this
contentView
, set top, bottom, left, and right margins to 0 pinning them to the Content Layout Guide of the scroll view;Now set the
contentView
's height equal to the Frame Layout Guide's height. Do the same for the width;Finally, set the priority of the equal height constraints to 250 (if you need the view to scroll vertically, the width to scroll horizzontally).
Finished.
Now you can add all your views in that contentView
, and the contentSize
of the scrollView
will be automatically resized according with the contentView
.
Don't forget to set the constraint from the bottom of the last object in your contentView
to the contentView
's margin.
Original [Deprecated]
So I just sorted out in this way:Inside the
UIScrollView
add aUIView
(we can call thatcontentView
);In this
contentView
, set top, bottom, left and right margins to 0 (of course from thescrollView
which is thesuperView
); Set also align center horizontally and vertically;
Scrollable content size is ambiguous to ScrollView
Here is the trick that worked for me:
Add a ScrollView to your wished ViewController.
Select it in the Outline and open its size inspector.
Uncheck there the option "Content Layout Guides".
Now set leading/top/trailing and bottom constrains to 0 of the ScrollView.
Add in a UIView and constrain its leading/top/trailing and bottom also to 0.
Add an equal width constrain to the UIView. (The width needs to be equal the width of the view from the ViewController, with this way you are disabeling horizontal scrolling).
The warning will disappear if every element inside the UIView is chained vertically. This means, that the top element has a constrain to the top of the view and to the element under it and so on. The last element needs a constrain to the bottom of the view.
If you followed this steps you should be fine with ScrollViews. This way you also can add as many content as you want to the bottom and the ScrollView will extend dynamically.
I hope I explained it well enough.
How to fix Scrollable Content Size Ambiguity in Xcode 11 (iOS 12, iOS 13) using Auto Layout
Disabling the content layout guides in the size inspector (ruler icon) in properties
I was having the same issue, and by disabling the option it was gone.
Hope it helps! :)
scrollview has ambiguous scrollable content height & Width
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
ScrollView has ambiguous scrollable content height
You need to ensure you've got a chain of vertical spacing constraints from the top of the scroll view through all your elements to the bottom of the scroll view.
Once you do that, your warning/error should go away.
UIScrollView has ambiguous scrollable content but it has no content
Presumably, you are laying this out with the intention of adding subviews (with proper constraints) to the scroll view at run-time.
But, Storyboard / Interface Builder has no idea what your code is going to do in the future.
You can either leave it as is and ignore the warning,
or
Tell Storyboard to stop warning you about it by selecting the scroll view and then selecting Ambiguity: Never Verify
in the size inspector pane:
or
Add some content, such as a UIView
that you will use to hold the UI elements you plan to add at run-time.
Related Topics
Determine Device (Iphone, Ipod Touch) With Ios
Programmatically Get Own Phone Number in Ios
Find If User Is in a Call or Not
How to Prevent Tableview Section Head from Sticking While Scrolling
Passing Data Between View Controllers
The Simplest Way to Resize an Uiimage
How to Show Verification Code Suggestion on Keyboard from Message
Transport Security Has Blocked a Cleartext Http
How to Link to Apps on the App Store
How to Add Spacing Between Uitableviewcell
Ansible Regex_Findall Multiple Strings
How to Create Delegates in Objective-C
Vertically Align Text to Top Within a Uilabel
How to Clear the Entered Textfield When the User Taps on the Button
Save Generated Gif to Camera Roll