0

I would like to align two views (in this case UIButton instances) next to each other. I want the first button to be left aligned to its superview, which is easy, but I don't see a way to make the second button aligned next to the first one without referencing the first ones width.

Here's what I'm trying right now:

    UIView *superView = ...;

    UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonOne.translatesAutoresizingMaskIntoConstraints = NO;
    [superView addView:buttonOne];
    [buttonOne constrainWidth:@"123" height:HEADER_HEIGHT_STRING];
    [buttonOne alignTop:nil leading:nil superView];

    UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonTwo.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:buttonTwo];
    [buttonTwo constrainWidth:@"345" height:HEADER_HEIGHT_STRING];
    [buttonTwo alignLeadingEdgeWithView:buttonOne predicate:@"123"]

How do I avoid the @"123" in the last line of the code? I want it to just use the width of buttonOne.

Edward Dale
  • 29,597
  • 13
  • 90
  • 129

1 Answers1

0

The answer in my case was not to use FLKAutoLayout and to learn to us. NSLayoutConstraint directly like so:

NSDictionary *views = NSDictionaryOfVariableBindings(buttonOne, buttonTwo);
[superView addConstraint:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[buttonOne][buttonTwo]-|" options:0 metrics:nil views:views]];
Edward Dale
  • 29,597
  • 13
  • 90
  • 129