Reputation: 473
Main question : I have three labels (label1, label2, label3) one below the other. How do I align label3 below label1 if, during runtime, label2 is set to hidden or if removed from superview.
Initial View:
Label1
vertical spacing
Label2
vertical spacing
Label3
Action:
set Label2.hidden = yes;
Output:
Label1
vertical spacing
Label3
What I have tried is to apply vertical spacing constraints:
Now when I remove the label2 how do I refresh the constraints or should I keep track of all constraints and remove the 2nd constraint when label2 is hidden?
Upvotes: 1
Views: 1347
Reputation: 19834
A solution would be to change the height constraint on label2 so that it's zero and then refresh the constraints so that everything moves up. You'd have to make a property of that variable and set it with +(id)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;
A couple tips:
Good luck!
Upvotes: 1
Reputation: 529
Why not just change label3's frame to equal label2 when you set it to hidden?
So add Label3.frame = Label2.frame;
after Label2.hidden = YES;
and vice versa.
Upvotes: 0