6

it seems I have created a simple Image view with the following constraints:

Align Center X to: Superview

Align Center Y to: Superview

Top Space to: Top Layout Guide

Bottom Space to: Bottom Layout Guide

And I have the Width and Horizontal Position Are Ambiguous message. I am trying to correct it, but I am not sure about what is happening in the first place.

Do you have an idea?

TechBee
  • 1,897
  • 4
  • 22
  • 46
Glyphs
  • 97
  • 1
  • 1
  • 7
  • you have no constraints for the width of the imageView. You could for example set the width to the width of the image. – Daniel Feb 09 '16 at 10:42
  • it seems ambiguous to me as well, because I don't see any constraints which makes the _horizontal_ position clarified; you may need to add either a _width_ or a _ratio_ constraint to resolve the ambiguity. – holex Feb 09 '16 at 11:11
  • your constraints are ambiguous. What do you want to do to the imageview. resize with the superview? or dont resize and stick to the center of the superview? – Sumeet Feb 09 '16 at 11:29
  • Actually, I want the view to resize, depending on the device, so I thought about linking it to the superview and let it do the resizing. Entering a fixed width wouldn't do. The width has to be dependent on the device. In the latest version of my app, I had a fixed width for each device, but there are now too many device sizes. I am trying to solve this without entering a new size each time. Is there a way to do this with constraints? – Glyphs Feb 09 '16 at 13:48

4 Answers4

5

You need to add the same constraint for left and right as you did for top and bottom.

Or set fixed width.

konrad.bajtyngier
  • 1,786
  • 12
  • 13
1

Remove Top Space to: Top Layout Guide and Bottom Space to: Bottom Layout Guide constraints, Set Image's Width and Height instead or (Width + Aspect ratio). Because every view needs x,y, height, width to render itself.

So You've already set X and Y using Align Center X to: Superview and Align Center Y to: Superview. So it needs specific width and height now.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
rushisangani
  • 3,195
  • 2
  • 14
  • 18
0

As you have told for constrainst: Align Center X to: Superview

Align Center Y to: Superview

Top Space to: Top Layout Guide

Bottom Space to: Bottom Layout Guide

The left option is of width Consider that any view which is placed behaves like expanding to and fro, we have to stablise it by putting constraints, your missing constraints for setting width (either from leading and trailing or from width) is making this issue

Devanshu Saini
  • 765
  • 5
  • 24
0

Go to Editor > Resolve Autolayout issue > Add Missing Constraint

Then the get the solution on the error page, what needs to be updated for example refer to the image where the height needs to be modified to 21 from 20

enter image description here

Bùi Đức Khánh
  • 3,975
  • 6
  • 27
  • 43