Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a view like this

 _______________________________
|     |                         |
|  Label 0                      |
|     ^                         |
|  Label 1                      |
|     ^                         |
|  Label 2                      |
|     ^                         |
|  Label N                      |
|_______________________________|

^ stands for a constraint that links the top of Label X+1 with the bottom of Label X. Label 0 is constrained to the superview's top with a fixed constant.

What I'm trying to achieve is: if some Label X is empty, then Label X+1 has to take its place.

 _______________________________
|     |                         |
|  Label 0 (empty)              |
|     ^                         |
|  Label 1                      |
|     ^                         |
|  Label 2                      |
|     ^                         |
|  Label N                      |
|_______________________________|
               |
               |   The new layout
              \ /
 _______________________________
|     |                         |
|  Label 1                      |  (here it is also Label 0 but is empty)
|     ^                         |
|  Label 2                      |
|     ^                         |
|  Label N                      |
|_______________________________|

Is this possible with auto layout or do I have to programatically check emptiness to update the constraints manually?

Disclaimer: If this questions sounds very basic excuse me, please, I'm migrating from springs and struts and it is a quite criptic for now.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Does it need to change when content is visible? If not try this: you could do an update in the viewWillAppear method. For each label, call

[firstLabel setNumberOfLines:0];
 [firstLabel setText:newProductTitleText];
 [firstLabel sizeToFit];

Setting number of lines to 0 lets the label dynamically use an many lines as it needs. If this is an empty label that should actually become 0 lines. This will update the frames and autolayout should take care of the rest.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.