-
-
Save heliang219/f4dbc3de98ed733d35fa663c711ec4c5 to your computer and use it in GitHub Desktop.
UILabel 并排 自适应 显示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
“Content Hugging Priority”,也叫内容紧靠优先级(小名:别扯我),该优先级越高,这越晚轮到被拉伸。 | |
“Content Compression Resistance Priority”,也叫内容压缩阻力优先级(小名:别挤我),该优先级越高,则越晚轮到被压缩。 | |
// ⤴️原文: https://www.jianshu.com/p/a4b8e0c8e68d | |
// 紧靠能力 优先级越低 内容显示得越完整 反之,内容被省略 | |
[self.nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; | |
[self.priceLabel setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]; | |
// 抗压缩能力 优先级越高 内容显示得越完整 反之,内容被省略 | |
[self.nameLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]; | |
[self.priceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; | |
/** | |
* 小结: | |
* Content Hugging Priority : 优先级越低 内容显示更完整,即优先显示 | |
* Content Compression Resistance Priority : 优先级越高 内容显示更完整,即优先显示 | |
* 设置优先级时最好再设置一个固定宽度(优先显示的label),并将该优先级设置低级 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment