Cocoa Autolayout:内容拥抱 vs 内容压缩阻力优先 [英] Cocoa Autolayout: content hugging vs content compression resistance priority

查看:23
本文介绍了Cocoa Autolayout:内容拥抱 vs 内容压缩阻力优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在关于 Cocoa Autolayout 的 Apple 文档中找到关于内容拥抱和抗压性之间差异的明确答案.

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 ?

推荐答案

概念的快速总结:

  • 拥抱 => 内容不想增长
  • 抗压性 => 内容不想收缩

示例:

假设你有一个这样的按钮:

Say you've got a button like this:

[       Click Me      ]

并且您已将边缘固定到优先级为 500 的更大的超级视图.

and you've pinned the edges to a larger superview with priority 500.

然后,如果拥抱优先级 > 500,它将如下所示:

Then, if Hugging priority > 500 it'll look like this:

[Click Me]

如果拥抱优先级<500 看起来像这样:

If Hugging priority < 500 it'll look like this:

[       Click Me      ]

如果 superview 现在缩小了,如果 Compression Resistance 优先级 > 500,它看起来像这样

If the superview now shrinks then, if the Compression Resistance priority > 500, it'll look like this

[Click Me]

否则,如果抗压优先级<500,它可能看起来像这样:

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!

例如您可以将其固定到优先级为 1000 的超级视图.或者你可以有一个宽度优先级.如果是这样,这可能会有所帮助:

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

这篇关于Cocoa Autolayout:内容拥抱 vs 内容压缩阻力优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆