Content Hugging and Compression Resistance Explained

脂习
• 阅读 1474

In a given view, there may be extra space horizontally and not enough vertically, or vice versa(或者相反). There may also be extra or not enough in both directions.

Suppose extra space is available for a view. Which control(控件)(subview) should grow to take the extra space? For that control, set hugging(紧抱)priority lower, and you are telling Auto Layout not to hug that control. In other words, that is the control you would like to grow(拉伸),(hugging priority:吸附能力、抗拉伸的权重)

Lower hugging priority means grow bigger. Higher hugging priority means stay(保持) the same and resist(抵抗) getting bigger

Suppose there is not enough space for a view. Which control (subview) should allow itself to be shrunk(压缩) or compressed? For that control(控件), set compression resistance priority lower, and you are telling Auto Layout that it can shrink this control because it is the one with the least resistance to being compressed.

Lower compression resistance means compress and make smaller. Higher compression resistance means stay the same and resist getting smaller

These are the tenets(原则) of Content Hugging Priority and Compression Resistance Priority. Auto Layout needs you to tell it how to handle cases of more or less space, otherwise the results may be unexpected and undesirable(不如所料的) when the size of a view changes or doesn’t match intrinsic content sizes.

Many controls have an intrinsic content size, which means the size it would like to be in order to accommodate (适应 )its content. For some controls, such as UIView, there is no intrinsic content size. Some controls have both a height and width intrinsic content size. Controls with both height and width intrinsic content size include UILabel and UIButton. 在XIB中UIImage在没有设置图片的时候没有intrinsic content,设置图片后就有了.

In general, controls have a default value of 250 for horizontal and vertical Content Hugging Priority, and a default value of 750 for horizontal and vertical Compression Resistance Priority. More about that shortly, but based on those defaults it is therefore easier to stretch(拉伸) than it is to shrink.

如果错误欢迎指正
原文链接:http://www.iosinsight.com/con...

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
橘子橙 橘子橙
4年前
vue-element-admin项目打包后,iconfont图标出现乱码
使用vueelementadmin或者vueelementtemplate开发的项目,打包到线上,就出现了图标乱码,f12后能看到icon元素为.eliconclose:before{content:"□"}的情况(如下)
Stella981 Stella981
3年前
Feign请求响应结果被截取com.fasterxml.jackson.core.io.JsonEOFException
在生产环境使用feign调用外部接口时,偶尔会出现下面错误2020101511:00:18,535ERRORcom.shein.abc.rmp.controller.RecExplainConfigControllerrec_explain_query.failffeign.codec.DecodeExc
Stella981 Stella981
3年前
AssemblyScript 入门指南[每日前端夜话0xEB]
每日前端夜话0xEB每日前端夜话,陪你聊前端。每天晚上18:00准时推送。正文共:2459 字预计阅读时间:10分钟作者:DannyGuo翻译:疯狂的技术宅来源:logrocket!(https://oscimg.oschina.net/oscnet/b880277c594152a503
Stella981 Stella981
3年前
Node.js 12中的ES模块[每日前端夜话0x9E]
每日前端夜话0x9E每日前端夜话,陪你聊前端。每天晚上18:00准时推送。正文共:2552字预计阅读时间:10 分钟作者:BrianDeSousa翻译:疯狂的技术宅来源:logrocket!(https://oscimg.oschina.net/oscnet/2ccaf94cecd3
Wesley13 Wesley13
3年前
MYSQL主从同步故障解决(主键重复)
MYSQL主从同步故障解决(主键重复)转载2010年04月05日18:52:00标签:mysql(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fso.csdn.net%2Fso%2Fsearch%2Fs.do%3Fq%
Stella981 Stella981
3年前
Flink SQL Window源码全解析
!(https://oscimg.oschina.net/oscnet/72793fbade36fc18d649681ebaeee4cdf00.jpg)(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MzgwNT
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
为什么mysql不推荐使用雪花ID作为主键
作者:毛辰飞背景在mysql中设计表的时候,mysql官方推荐不要使用uuid或者不连续不重复的雪花id(long形且唯一),而是推荐连续自增的主键id,官方的推荐是auto_increment,那么为什么不建议采用uuid,使用uuid究
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
脂习
脂习
Lv1
看不清的挽留,正如你执着地向前走
文章
3
粉丝
0
获赞
0