How to resolve inequality constraint ambiguity - vertical ambiguous in AutoLayout in iOS

2.6k Views Asked by At

In my iOS application, I have enabled Use Auto Layout option and I'm using storyboards to design my UI. There in one of my View I'm having UIDatePicker with following constraints.

  • Trailing space to: Superview
  • Leading space to: Superview
  • Bottom space to: MyUILabel Equal <= 20
  • Top space to: MyImageView = 20

The highlighted constraint gives me following warning

Inequality Constraint Ambiguity

When I see the issue using Issue Navigator, it tells me

Ambiguous Layout MyUILabel is vertically ambiguous.

That MyUILabel is having following constraints

  • Trailing space to: Superview
  • Leading space to: Superview
  • Top space to: UIDatePicker <= 20
  • Bottom space to: AnotherUILabel = 20

Why I need this kind of constraint is when I load the application in 3.5 inch screens some of my bottom UI elements overlapped. By adding that highlighted constraints solve that issue and give me two separate issues.

The first one is the above mention Inequality Constraint Ambiguity and the second one is, even in 4 inch screen size this constraint is getting apply. I mean for 4 inch screen sizes and above I can have Bottom space to: MyUILabel Equal = 20 and it appears fine without any overlapping.

How can I solve this?

Simply I need having <= 20 constraint for 3.5 inch screens and = 20 constraint for 4 inch and above screen sizes.

Thanks in advance.

1

There are 1 best solutions below

0
On

Its hard to tell without seeing your whole view. Base on your description, I would check your topmost view to make sure its vertically pinned to it's superview. For your case I think that is the "MyImageView"; try setting it's "Top Space to Superview/Top Layout Guide" equal to 10/15/etc whatever you want.