1.自适应宽度
前提不需要设置label的宽度
//宽度够时
[yourLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
宽度不够时
[yourLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
2.label多行自适应高度
label.preferredMaxLayoutWidth = width;//给一个maxWidth
[label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];//设置huggingPriority
label.numberOfLines = 0;//设置换行
网友评论