Reputation: 27
I have 3 hidden Labels, after a check from database i set label.isHidden = false
only if the value of that label exists.
This is the situation when all labels have right value
So I'm using Storyboard with AutoLayout for determinate the position of these labels but i need to pull labels to left if one of these still hidden keeping the space with other labels.
Is it possible to do it programmatically? If yes, how?
Upvotes: 0
Views: 454
Reputation: 2149
Use StackView for this. You don't have to do tiring auto-layout if you use StackView.Rather you will find what you want
After clicking hide.
After clicking show
Upvotes: 1
Reputation: 121
Use StackView to handle this Space instead of using isHidden to hide the label.
You can also achive that by AutoLayout, use yourConstraint.constant = 0 or priority property of the constraints.
Upvotes: 0
Reputation: 1613
One way to achieve this would be to align each label relative to the adjacent label (label1.trailing to label2.leading for example).
Then instead of setting any label to hidden you can set the width constraint to 0 and call layoutIfNeeded
on the superview, all other labels will then layout accordingly.
Upvotes: 1