可可自动布局:内容拥抱VS内容融为一体pression性优先 [英] Cocoa Autolayout: content hugging vs content compression resistance priority

查看:324
本文介绍了可可自动布局:内容拥抱VS内容融为一体pression性优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到有关可可自动布局有关内容拥抱和COM pression性之间的区别在苹果的文档明确的答案。

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 ?

推荐答案

的概念快速总结:


  • 抱死=>内容并不想成长

  • 的COM pression电阻=>内容并不想缩小

和一个例子:

假设你有按钮,就像这样:

Say you've got button like this:

[       Click Me      ]

和你固定的边缘,更大的SuperView优先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然后收缩,如果COM pression性优先级> 500,它会看起来像这样

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

[Click Me]

否则,如果的COM pression阻力优先&LT; 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

这篇关于可可自动布局:内容拥抱VS内容融为一体pression性优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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