Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The issue is how you've defined your button's top constraint. If it's to the label, when you adjust the label's height constraint, the button will move. For example, if doing it programmatically:</p> <pre><code>UILabel *label = [[UILabel alloc] init]; label.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:label]; label.text = @"Hello world"; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:@"Submit" forState:UIControlStateNormal]; button.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:button]; NSDictionary *views = NSDictionaryOfVariableBindings(label, button); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[label]" options:0 metrics:nil views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[button]" options:0 metrics:nil views:views]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[label]-[button]" options:0 metrics:nil views:views]]; NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20]; [label addConstraint:heightConstraint]; </code></pre> <p>Then, if you change the label's height constraint, the button will move:</p> <pre><code>heightConstraint.constant = 100; [UIView animateWithDuration:1.0 animations:^{ [self.view layoutIfNeeded]; }]; </code></pre> <p>If you've defined your UI in Interface Builder, select the button and check the top constraint of the button and make sure it's to the label, not the superview:</p> <p><img src="https://i.stack.imgur.com/5k8NP.png" alt="top constraint"></p> <p>But, again, if the button's top constraint is to the label, when the label's height constraint changes, the button will move.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload