1. 什么是Content hugging priority

你可以把它想象成一根放在视图上的橡皮筋。

这根橡皮筋会组织视图超过它本身的固有大小(intrinsic content size)。

它存在一个优先级,从0到1000。

1000表示视图绝对不能超过intrinsic content size。

我们来看个例子:

上图中有两个横向排列的标签控件(label),并且你也已经设置好了约束。

这个会工作正常,直到父视图变宽的时候。

那么,问题来了。

如果父视图变宽了,那个label应该变宽呢?

这个时候正是我们用到Content hugging priority的时候。

拥有高优先级Content hugging priority的视图控件将不会被拉伸。

你可以把这个优先级想象成橡皮筋的抗拉伸力。

这个优先级越大,视图将越希望保持自己的固有大小(intrinsic content size)。

2. Content compression resistance priority

和Content hugging priority相反,Content compression resistance priority是用来抵抗压缩的。

简单的来说,前者我们讨论过的,是抵抗拉伸,也就是抵抗变大,而后者是抵抗压缩,也就是抵抗变小。

还是上面的例子中,当父视图变小的时候,拥有高优先级的label将不会被压缩,因而标签上的文本也就不会被截断。

iOS开发 - Content hugging priority & Content compression resistance priority的更多相关文章

  1. iOS开发之AutoLayout中的Content Hugging Priority和 Content Compression Resistance Priority解析

    本篇博客的内容也不算太复杂,算是AutoLayout的一些高级的用法.本篇博客我们主要通过一些示例来看一下AutoLayout中的Content Hugging Priority以及Content C ...

  2. AutoLayout学习之理解intrinsicContentSize,Content Hugging Priority,Content Compression Resistance Priority

    TableViewCell的高度计算应该是所有开发者都会使用到的东西,之前都是用代码计算的方法来计算这个高度.最近有时间看了几个计算Cell高度的方法.基本上都用到了AutoLayout,这篇首先介绍 ...

  3. 转:AutoLayout中的Content Hugging 和 Content Compression Resistance

    OS6中引入了AutoLayout,极大的方便了UI元素的布局,现在已经过去一年了,并且大部分设备的系统也已经升级到了iOS6,是时候要使用此项技术了. 在AutoLayout的学习中有两个概念官方文 ...

  4. iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】

    原文:http://www.mgenware.com/blog/?p=491 接上文:iOS: 在代码中使用Autolayout (1) – 按比例缩放和优先级. 我们继续来看在代码中使用Autola ...

  5. intrinsicContentSize和Content Hugging Priority

    Mgen | 首页 | | 发新文章 | 联系 | 订阅  | 管理 iOS: 在代码中使用Autolayout (2) - intrinsicContentSize和Content Hugging ...

  6. 在代码中使用Autolayout – intrinsicContentSize和Content Hugging Priority

    我们继续来看在代码中使用Autolayout的话题.先说intrinsicContentSize,也就是控件的内置大小.比如UILabel,UIButton等控件,他们都有自己的内置大小.控件的内置大 ...

  7. iOS 开发实践之 Auto Layout

    原:http://xuexuefeng.com/autolayout/?utm_source=tuicool 本文是博主 iOS 开发实践系列中的一篇,主要讲述 iOS 中 Auto Layout(自 ...

  8. iOS 开发中遇到的问题

    1. 关于纠结很久的KVO崩溃问题,其真正原因是,在删除roomItem的KVO之前,将这个对象已经赋值为nil,所以实际上并没有删除他的observer,因此而崩溃:长时间纠结的原因是受.cxx_d ...

  9. Android开发-API指南-创建 Content Provider

    Creating a Content Provider 英文原文:http://developer.android.com/guide/topics/providers/content-provide ...

随机推荐

  1. spring Quartz基于配置文件和注解的实现

    这里仅仅是做简单的记录怎样实现. 一.基于配置文件的实现 ①编写须要调度的类 package com.study; import org.springframework.scheduling.anno ...

  2. Visual Studio 2013 sqlce 配置(转)

    Visual Studio 2013 把內建 SQL CE 的管理工具拿掉了 下载SQL Server Compact Toolbox by ErikEJ并安装 打开VS2013,新建一工程,在“视图 ...

  3. C#编程(三十五)----------foreach和yield

    枚举 在foreach语句中使用枚举,可以迭代集合中的元素,且无需知道集合中的元素个数. 数组或集合实现带GetEumerator()方法的IEumerable接口.GetEumerator()方法返 ...

  4. 【Devops】【docker】【CI/CD】1.docker搭建Gitlab环境

    CI/CD[持续化集成/持续化交付] docker搭建Gitlab环境 1.查询并拉取gitlab镜像 docker search gitlab docker pull gitlab/gitlab-c ...

  5. CSS:如何学习 CSS?

    马上该转战互联网领域了,在此总结一下 CSS 学习的思路. 理解 CSS 的基本语法. 理解盒子模型. 理解文档流和定位. 理解浮动和清除. 理解各种 CSS 样式. 目前发现的最好的资源是:http ...

  6. blob转base64位 base64位转blob

    //**dataURL to blob** function dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0]. ...

  7. [Web 前端] Jquery实现可直接编辑的表格

    cp from :https://www.cnblogs.com/sjqq/p/6392001.html?utm_source=itdadao&utm_medium=referral 文实例讲 ...

  8. Could not install packages due to an Environment Error: [Errno 13] Permission denied 解决方案

    执行pip install 报错如下: Could not install packages due to an Environment Error: [Errno 13] Permission de ...

  9. JQuery的ajaxFileUpload的使用

    https://www.cnblogs.com/zhanghaoliang/p/6513964.html 最近在工作中使用了Jquery的ajaxFileUpload的图片上传插件,感觉这种异步上传的 ...

  10. [leetcode]Permutations @ Python

    原题地址:https://oj.leetcode.com/problems/permutations/ 题意: Given a collection of numbers, return all po ...