Reputation: 5817
I have a table view with a textfield on the left hand side of a cell and on the right hand side there is a label.
The constraints of the label are very fixed, with a fixed width, vertical center of the container and fixed distance to the right edge of the container.
The constraints of the textfield are variable. It has a fixed position to the left side of the container, also vertical center of the container and a fixed distance to the right edge of the container. But since no width is set, the width is actually variable, depending on the device my app is used.
Now, in edit mode I hide the label and only show the textfield. So I would like to decrease the spacing of the textfield to the right end of the container since no label is in the way. But how can I do this in code? All constraints are set in XCode and I have no experience in doing this with code...
Edit: Screenshot
Upvotes: 0
Views: 408
Reputation: 2383
If I understand your question correctly, you could setup an IBOutlet from your right (Trailing) constraint to your UITableViewCell. Then, in your UITableViewCell, change the constant of the right (Trailing) constraint.
Ex.
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textFieldTrailingSpaceToViewConstraint;
[self layoutIfNeeded];
[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^
{
[textFieldTrailingSpaceToViewConstraint setConstant: 100];
[self layoutIfNeeded];
} completion:nil];
Upvotes: 1