Using Masonry to Layout 9 points

53 Views Asked by At

I'm using Masonay to layout UI like this: UI requirement

The size of the 9 points are the same. And the margin between 9 points are the same. My question is that how to make margin to left of first column point equal to the margin to the right of the last column points by using Masonay ? My code blow is not complete. Can anyone help me with this?

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

There are 0 best solutions below