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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With