0

我想将两个视图(在这种情况UIButton下)彼此对齐。我希望第一个按钮与其超级视图左对齐,这很容易,但我没有看到一种方法可以使第二个按钮与第一个按钮对齐而不参考第一个按钮的宽度。

这是我现在正在尝试的:

    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"]

如何避免@"123"在代码的最后一行出现?我希望它只使用buttonOne.

4

1 回答 1

0

就我而言,答案是不要向FLKAutoLayout我们使用和学习。NSLayoutConstraint直接像这样:

NSDictionary *views = NSDictionaryOfVariableBindings(buttonOne, buttonTwo);
[superView addConstraint:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[buttonOne][buttonTwo]-|" options:0 metrics:nil views:views]];
于 2013-05-26T01:46:11.020 回答