Cocoa Autolayout: content hugging vs content compression resistance priority
I can't find a clear answer on Apple documentation regarding Cocoa Autolayout about the difference between content hugging and compression resistance.
Can somebody explain their usages and difference ?
Quick summary of the concepts:
and an example:
Say you've got button like this:
[ Click Me ]
and you've pinned the edges to a larger superview with priority 500.
Then, if Hugging priority > 500 it'll look like this:
[Click Me]
If Hugging priority < 500 it'll look like this:
[ Click Me ]
If superview now shrinks then, if the Compression Resistance priority > 500, it'll look like this
[Click Me]
Else if Compression Resistance priority < 500, it could look like this:
[Cli..]
If it doesn't work like this then you've probably got some other constraints going on that are messing up your good work!
Eg you could have it pinned to the superview with priority 1000. Or you could have a width priority. If so, this can be helpful:
Editor > Size to Fit Content
Take a look at this video tutorial about Autolayout, they explain it carefully
source: @mokagio
Intrinsic Content Size - Pretty self-explanatory, but views with variable content are aware of how big their content is and describe their content's size through this property. Some obvious examples of views that have intrinsic content sizes are UIImageViews, UILabels, UIButtons.
Content Hugging Priority - The higher this priority is, the more a view resists growing larger than its intrinsic content size.
Content Compression Resistance Priority - The higher this priority is, the more a view resists shrinking smaller than its intrinsic content size.
Check here for more explanation: AUTO LAYOUT MAGIC: CONTENT SIZING PRIORITIES
链接地址: http://www.djcxy.com/p/91586.html