SoFunction
Updated on 2025-04-12

How to resolve iOS constraint conflict

iOS constraint conflicts are generally divided into two categories: margin constraint conflicts or size conflicts. Usually, the constraint priority of one of the controls can be modified, which uses content Hugging/content Compression Resistance. The prerequisite for use requires determining the size of its control, which is generally used after the autolayout is successfully constrained.

Set the maximum priority. As long as the control is set to be higher than the other one, you can ensure that another constraint is changed when a constraint conflict occurs.

- (void)setContentHuggingPriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);

Similarly, you can set the minimum priority of the control

- (void)setContentCompressionResistancePriority:(UILayoutPriority)priority forAxis:(UILayoutConstraintAxis)axis NS_AVAILABLE_IOS(6_0);

* Intrinsic Content Size: Intrinsic size. Controls such as UIView have their own intrinsic size.

Also attached:

// Otherwise, it is inaccurate on 6/6plus = SCREEN_WIDTH - 40;

The above is the solution to iOS constraint conflict introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!