I am trying to align two Button in a View (appears in cyan). They are aligned vertically in the View . When I try to level them horizontally, their heights change. I want their width to be the same according to the width of the superview, unlike the smaller Next button. Can this be done only with VFL ?

Here is the code:
[self prepareButton:saveButton label:@"SAVE"]; [buttonContainerView addConstraint:[NSLayoutConstraint constraintWithItem:saveButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:buttonContainerView attribute:NSLayoutAttributeCenterY multiplier:1.00f constant:0]]; [saveButton layoutIfNeeded]; [self prepareButton:nextButton label:@"NEXT"]; [buttonContainerView addConstraint:[NSLayoutConstraint constraintWithItem:nextButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:buttonContainerView attribute:NSLayoutAttributeCenterY multiplier:1.00f constant:0]]; [nextButton layoutIfNeeded]; [buttonContainerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[saveButton]-[nextButton]-|" options:0 metrics:metrics views:viewDictionary]]; [saveButton layoutIfNeeded]; [nextButton layoutIfNeeded]; -(void)prepareButton:(UIButton *)button label:(NSString *) label { [buttonContainerView addSubview:button]; button.translatesAutoresizingMaskIntoConstraints = NO; button.backgroundColor = [UIColor redColor]; button.layer.cornerRadius = 2.50f; [button setTitle:label forState:UIControlStateNormal]; [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; }
source share