Reputation: 9273
I can't understand how can I solve this auto layout problem, i have this View:
There is an UIScrollView with the elements you see in the View, but the View gives me this warning:
scrollview has ambiguous content width
I can't understand how to solve this problem, I want the the view is for the full screen size, and I want that the width will be the screen width, how I can solve it?
Upvotes: 8
Views: 11774
Reputation: 1915
I too faced this issue and the only way i got it solved was using the below strategy
This should do it now you can follow step 3 and continue with your UI
Hope it helps
Upvotes: 0
Reputation: 12908
I observed its fix in XCode 7.3 and it is just 10 sec work. I made a video on it. Check here:
https://www.youtube.com/watch?v=yETZKqdaPiI
All you have to do, add a subview to UIScrollView
with same width and height
. Then select ViewController
and press Reset to suggested constraint
. Please check video for clear understanding.
Thanks
Upvotes: 3
Reputation: 645
The solutions is:
You have a UIImageView at the top. You set the width of the UIImageView to be the same as the width of the root view of the UIViewController
You set the leading and trailing space of the UIImageView to the UIScrollView to be both 0
You set the height of the UIImageView to be the height you want the image to be. And then you set the view mode of the UIImageView to be 'Aspect fit'.
Upvotes: 2
Reputation: 1141
I had the same problem a month ago. Add a constraint that makes the UIView
inside the UIScrollView
have the same size of the UIScrollView
's content width. If you have multiple views inside the UIScrollView
, put your UIView
s inside a new UIView
and make sure the new UIView
has the same content width size as the UIScrollView
.
Best regards,
Upvotes: 0
Reputation: 5195
Put everything in a View and that View put inside a ScrollView.
Editor -> Embed in -> View
Upvotes: 2
Reputation: 761
This is because you are not providing enough constraints so that Xcode can find Width of your scroll view. You can see on your screen there isn't any constraints that can be satisfied to find width of scroll view.
You can do it by providing leading and trailing space of Image view which contains fix width. It also can be done with any other views. But i will prefer control which contains fix Height & Width So there isn't require to set hugging priority or Compress resistance.
Upvotes: 2