UITableViewCell 中包含多个UILabel如何布局

记录一个暂未解决的问题。

Paste_Image.png

一个tablevicecell 中包含的元素全部是UILabel,以现在的技术无法做到cell 自适应高度,之前用的一套自适应机制目前无法实现。。先挖坑,记录下

Autolayout小结(二)
这边文章有个思路,还没有试。

Paste_Image.png

Multiple UILabels inside a self sizing UITableViewCell

这个还没有细看。

ios Content Hugging

  • 2016/8/18
    牵扯到几个概念:

Content Compression Resistance
Content Hugging
英文意思。(囧RZ。英语渣的苦恼)
Content :内容
Compression:压缩
Resistance:抵抗、阻力
Hugging:拥抱

参考:IOS开发之Autolayout——“Content Compression Resistance”和“Content Hugging”
“Content Compression Resistance Priority”,也叫内容压缩阻力优先级(小名:别挤我),该优先级越高,则越晚轮到被压缩。
“Content Hugging Priority”,也叫内容紧靠优先级(小名:别扯我),该优先级越高,这越晚轮到被拉伸。

参考:Cocoa Autolayout: content hugging vs content compression resistance priority
Quick summary of the concepts:
Hugging => content does not want to grow
Compression Resistance => content does not want to shrink
and an example:
Say you've got button like this:
[ Click Me ]
and you've pinned the edges to a larger superview with priority 500.
Then, if Hugging priority > 500 it'll look like this:
[Click Me]
If Hugging priority < 500 it'll look like this:
[ Click Me ]
If superview now shrinks then, if the Compression Resistance priority > 500, it'll look like this
[Click Me]
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!
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

马丹,因为这几个英文单词我又去搜索怎么背单词去了。老是犯这种毛病,不专注!!

搞定!!!

Paste_Image.png

要点就是上面提到的两个属性。

“Content Compression Resistance Priority”,也叫内容压缩阻力优先级(小名:别挤我),该优先级越高,则越晚轮到被压缩。
“Content Hugging Priority”,也叫内容紧靠优先级(小名:别扯我),该优先级越高,这越晚轮到被拉伸。

Paste_Image.png

稍后忙完这段时间 整理出一片文章出来。

推荐阅读更多精彩内容