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!
E.g. 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容