什么是一个UIView的内容融为一体pression性和内容的拥抱? [英] What is the content compression resistance and content hugging of a UIView?

查看:114
本文介绍了什么是一个UIView的内容融为一体pression性和内容的拥抱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一个UIView的内容融为一体pression性和内容的拥抱?如何将这些涉及到一个视图的内在内容大小?

What is the content compression resistance and content hugging of a UIView? How do these relate to the intrinsic content size of a view?

推荐答案

objc.io 的出色的Advanced自动布局工具箱文章

本质内容大小

内在含量的大小是大小的视图prefers有它显示的具体内容。例如,的UILabel具有基于字体的preferred高度,并基于字体,并显示文本的preferred宽度。一个UIProgressView只有基于其作品一preferred高度,但没有preferred宽度。一个普通的UIView既没有preferred宽度也不是preferred高度。

The intrinsic content size is the size a view prefers to have for a specific content it displays. For example, UILabel has a preferred height based on the font, and a preferred width based on the font and the text it displays. A UIProgressView only has a preferred height based on its artwork, but no preferred width. A plain UIView has neither a preferred width nor a preferred height.

的COM pression阻力和内容抱死

每个视图包含内容
  COM pression性的优先事项和内容拥抱优先
  分配给两个维度。这些属性才生效的
  它定义了一个内在的内容大小的意见,否则就没有
  内容大小定义,可以抵御COM pression或者拥抱。

Each view has content compression resistance priorities and content hugging priorities assigned for both dimensions. These properties only take effect for views which define an intrinsic content size, otherwise there is no content size defined that could resist compression or be hugged.

场景,内在含量的大小和这些优先的背后
  值会转换成约束。对于具有本征的标签
  {的100,30}内容大小,水平/垂直COM pression
  750阻力优先级和水平/垂直内容的拥抱
  250优先,四约束将产生

Behind the scenes, the intrinsic content size and these priority values get translated into constraints. For a label with an intrinsic content size of { 100, 30 }, horizontal/vertical compression resistance priority of 750, and horizontal/vertical content hugging priority of 250, four constraints will be generated:

H:[label(<=100@250)] 
H:[label(>=100@750)]
V:[label(<=30@250)]
V:[label(>=30@750)]

如果你不熟悉的视觉语言格式
  上面使用的限制,你可以在苹果的大约读了它
  文档。牢记这些附加的约束
  产生的隐含有助于了解自动布局的行为,并
  使其错误信息的更好的理解。

If you’re not familiar with the visual format language for the constraints used above, you can read up about it in Apple’s documentation. Keeping in mind that these additional constraints are generated implicitly helps to understand Auto Layout’s behavior and to make better sense of its error messages.

这是另一个问题,计算器,解决内容融为一体pression性与放大器之间的差异;内容拥抱:
<一href=\"http://stackoverflow.com/questions/15850417/cocoa-autolayout-content-hugging-vs-content-com$p$pssion-resistance-priority\">Cocoa自动布局:内容拥抱VS内容融为一体pression性优先

Here's another StackOverflow question that addresses the difference between content compression resistance & content hugging: Cocoa Autolayout: content hugging vs content compression resistance priority

这篇关于什么是一个UIView的内容融为一体pression性和内容的拥抱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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