天天看點

Cocoa Autolayout: content hugging vs content compression resistance priority

URL:http://stackoverflow.com/questions/15850417/cocoa-autolayout-content-hugging-vs-content-compression-resistance-priority

Quick summary of the concepts:

  • Hugging => content does not want to grow
  • Compression Resistance => content does not want to shrink

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!

繼續閱讀