Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autolayout Constraints Priority

I have 2 UILabel labelA and labelB and a width of 320 px. I created constraints

H:|-[labelA]-(>=4)-[labelB]-|

Unfortunately, labelA and labelB can sometime be big and would not fit without truncation. I would like to make sure that no matter what, labelB will not get truncated. (labelB will not go over 160 px). However, I would like to use the available space for labelA as much as possible so fixing labelB to half is just a waste of space.

Question: How do I put a priority such that labelB always retain its intrinsic size? Where as labelA can get truncated.

like image 299
Byte Avatar asked Aug 30 '13 15:08

Byte


1 Answers

You set the content compression resistance to high on label B:

[labelB setContentCompressionResistancePriority: UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

This means that B will try not to be compressed below the intrinsic size given by the text. To make it also be as small as possible, you may also want to set the contentHuggingPriority- this will make it try to match the size of the text.

like image 130
jrturton Avatar answered Sep 29 '22 12:09

jrturton