I am using this code:
- (void)replaceTopConstraintOnView:(UIView *)view withConstant:(float)constant
{
[[[self contentView] constraints] enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop) {
if ((constraint.firstItem == view) && (constraint.firstAttribute == NSLayoutAttributeLeft)) {
constraint.constant = constant;
}
}];
}
when I set text in my label I change constraint from the -100 to 10.
- (void)setText:(NSString *)text
{
[[self label] setText:text];
[self replaceTopConstraintOnView:[self label] withConstant:10];
[[self contentView] layoutIfNeeded];
}
Here is how I configure label constarint at initialization:
Init of table view cell method:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
[NSLayoutConstraint constraintWithItem:[self label]
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:[self containerView]
attribute:NSLayoutAttributeLeft
multiplier:1.0f
constant:-100];
So it does not work for me. I don't describe animation here. But it even does not work without UIView animation block. I've debuted it the constraints constant was changed to 10 but I still don't see label. So the label also has width and hight. And If I set constraint to 10 at start I see my label.