5

I am trying to set a UIImageView has no fixed size and width in the storyboard. I set the leading space to container to greater than or equal to 20, top space to the container to greater than or equal to 20 and trailing space to container to greater than or equal to 20 and vertical spacing to a UICollectionView, the UICollectionView satisfy the constraints. But the UIImageView don't work, it's telling me it's Position and size are ambiguous. How can I make it work? My Idea is no matter how large the image view, it will always keep 20 space to leading, top, trailing and bottom.

I have set the height and width to be greater than or equal to some value and their priority to 999, it's lower than the leading, top and trailing priority. and I have set the imageview to center horizontally. but i get height and vertical position are ambiguous for “Image view”.

Community
  • 1
  • 1
yong ho
  • 3,892
  • 9
  • 40
  • 81

5 Answers5

9

Can you see what happens when you add height and width constraints to the UIImageView, but set their priorities to some low value, e.g. 1? It should help, but now UIImageView won't be centered. You can fix it by enclosing UIImageView in another view (empty UIView) and centering it in it both horizontally and vertically.

Arek Holko
  • 8,966
  • 4
  • 28
  • 46
  • 1
    I have set the height and width to be greater than or equal to some value and their priority to 999, it's lower than the leading, top and trailing priority. and I have set the imageview to center horizontally. but i get height and vertical position are ambiguous for “Image view”. – yong ho Oct 12 '13 at 01:40
  • 2
    @yongho Leave your constraints as they're but ADD new constraints for width and height (EQUAL, not greater than or equal) with priority equal to 1. Just think about it: if there's no image set (please read about `intrinsicContentSize`) and all you have are two "greater than or equal" constraints, then Auto Layout won't know what margins you want, because many pairs would satisfy constraints. – Arek Holko Oct 12 '13 at 08:48
  • Thanks it worked. Although it says the vertical position is ambiguous, but the lines are finally all blue. – yong ho Oct 14 '13 at 05:26
  • @yongho: I've made a similar layout and I'm not getting the warning about ambiguous vertical position. So, I'm not sure why it happens. – Arek Holko Oct 14 '13 at 07:40
2

When you get this error:

Position and size are ambiguous for “view”

Probably following constraints are missing/incorrectly set:

  1. Width constraint (size issue)
  2. Height constraint (size issue)
  3. Alignment constraints (position issue)
Sumoanand
  • 8,835
  • 2
  • 47
  • 46
2

If you are using Stack Views, make sure the Photo Image View is inside the Stack View! (As in the Apple Tutorial)

  • And also for UIStackView see [here](https://stackoverflow.com/questions/45428953/height-and-vertical-position-are-ambiguous-for-uistackview/45428954#45428954) – SparkyRobinson Aug 01 '17 at 04:27
  • 1
    That was it for me, thanks! I'm working on the `FoodTracker` tutorial and I failed to include the `UIImageView` inside the `Stack View`. – Andi Feb 23 '18 at 17:29
0

If you want to give margin kind of thing into button through coding than please try these if it'll work

[button_Name setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 12.0, 0.0, 0.0)];

I hope this will work..!!!

Indra
  • 528
  • 2
  • 11
0

In cases where the height/width are not ambiguous at runtime, but ambiguous at storyboard time, e.g., setting an image dynamically, having a container view, etc, I try to add constraints with the placeholder checkmark checked to silence xcode.

moger777
  • 1,117
  • 11
  • 16