1. What is content hugging priority
You can think of it as a rubber band placed on the view.
This rubber band organizes the view beyond its intrinsic size (intrinsic content size).
It has a priority, from 0 to 1000.
1000 indicates that the view must never exceed intrinsic content size.
Let's look at an example:
There are two horizontally arranged label controls (labels), and you've set up the constraints as well.
This will work fine until the parent view becomes wider.
So, here's the problem.
If the parent view becomes wider, should the label be wider?
This is when we use content hugging priority.
View controls that have high-priority content hugging priorities will not be stretched.
You can think of this priority as the tensile strength of a rubber band.
The larger the priority, the more the view will want to maintain its intrinsic size (intrinsic content size).
2. Content Compression Resistance priority
Contrary to content hugging priority, the content compression resistance priority is used to resist compression.
In short, the former we have discussed is the resistance to stretching, that is, the resistance to become larger, and the latter is to resist compression, that is, the resistance becomes smaller.
In the example above, when the parent view becomes smaller, the label with the high priority will not be compressed, so the text on the label is not truncated.
iOS development-Content hugging priority & content compression resistance priority