使用Masonry布局9点

时间:2016-06-12 08:02:52

标签: ios ios-autolayout masonry-ios-osx

我正在使用Masonay来布局这样的UI: UI requirement

9分的大小是相同的。 而9点之间的差距是相同的。 我的问题是如何使第一个列点左边的边距等于最后一列右边的边距使用Masonay ? 我的代码打击不完整。 任何人都可以帮我这个吗?

for (NSInteger i = 0; i < 9; i++) {
    NSInteger row = i / 3;
    NSInteger column = i % 3;
    UIView * previousRowPoint;
    UIView * previousColumnPoint;
    UIView * firstPoint;
    if (row > 0) {
        previousRowPoint = hintPoints[(row - 1) * 3];
    }
    if (column > 0) {
        previousColumnPoint = hintPoints[column - 1];
    }
    if (0 != i) {
        firstPoint = hintPoints[0];
    }
    UIView * hintPoint = [[UIView alloc] init];
    [hintPoints addObject:hintPoint];
    hintPoint.layer.cornerRadius = 8 / 2;
    hintPoint.layer.masksToBounds = YES;
    hintPoint.layer.borderColor = [UIColor grayColor].CGColor;
    hintPoint.layer.borderWidth = 0.5;
    [self.view addSubview:hintPoint];
    hintPoint.mas_key = [NSString stringWithFormat:@"hintPoint_%ld", (long)i];
    [hintPoint mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(8);

        if (row == 0) {
            make.top.equalTo(weakself.view).offset(100);
        }
        else {
            make.top.equalTo(previousRowPoint.mas_bottom).offset(4);
        }

        if (column == 0) {
            //TODO: how to make the trailing equal to the first point's leading
        }
        else if (column == 2) {
            //TODO: how to make the trailing equal to the first point's leading
        }
        else {
            make.leading.equalTo(previousColumnPoint.mas_trailing).offset(4);
        }
    }];
}

0 个答案:

没有答案