I create a rect with following constraints:
I though if i set priority to constraints with width >=250
to 999
, then width equal == 200
will work on small devices, and with width >= 250
on large.
But it is not worked. I read documentation:
After solving for the required constraints, Auto Layout tries to solve all the optional constraints in priority order from highest to lowest. If it cannot solve for an optional constraint, it tries to come as close as possible to the desired result, and then moves on to the next constraint.
This combination of inequalities, equalities, and priorities gives you a great amount of flexibility and power. By combining multiple constraints, you can define layouts that dynamically adapt as the size and location of the elements in your user interface change.
The priority for the constrains will be applied in order to resolve a conflict between two different constraints. The frame's view will be modified applying the constraint with more priority. So, you should have another view or use the superview to apply the priority to the constraints.
This is a nice answer explaining the resistance priority:
Cocoa Autolayout: content hugging vs content compression resistance priority
iOS does what you tell. Constraints do not disable automatically depending on screen sizes. Constraints with higher priority will be applied first.
So, when iOS needs to layout your view, it will lookup the specifications that you provided. Now, according to your given specification, the view should have the width of 200 (highest priority) irrespective of screen sizes. So this constraint is applied and you get your view with width of 200.
How can you do what you want?
You should try to disable the constraint with "width" specification of 200, when your app is running on large screen then your other constraint will work and give correct result.
For disabling/enabling constraint -
Stackoverflow Link
Apple Developer Library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With