I’ll post to you all. I’ll post to you for navigation. You can log it to others you might not know about.

First, explain the relevant API

** * distribute with fixed spacing ** @param axisType horizontal or vertical * @param fixedSpacing two controls * @param leadSpacing First control with the edge of the interval * @ param tailSpacing finally a control with the edge of the interval * / - (void) mas_distributeViewsAlongAxis: (axisType MASAxisType) withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; ** * distribute with fixed item size ** @param axisType horizontal or vertical * @param fixedItemLength Width or height of the control * @param leadSpacing First control with the edge of the interval * @ param tailSpacing finally a control with the edge of the interval * / - (void) mas_distributeViewsAlongAxis: (axisType MASAxisType) withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;Copy the code

Two API, divided into fixed interval not fixed width and height, fixed width and height not fixed interval, according to specific needs to use the corresponding.

Note that: horizontal to set the corresponding control array vertical constraints, vertical to set the corresponding control number horizontal constraints.

Second, specific practice test

To do the preparatory work first, Sir Into four views (need to be arranged), the code is as follows:

- (NSMutableArray *)masonryViewArray {

    if(! _masonryViewArray) { _masonryViewArray = [NSMutableArray array];for(int i = 0; i < 4; i ++) { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor redColor]; [self.view addSubview:view]; [_masonryViewArray addObject:view]; }}return _masonryViewArray;
}Copy the code

1, horizontal arrangement, fixed control interval, control length variable

The test code is as follows

- (void)test_masonry_horizontal_fixSpace {// implement the navigation level fixed interval method mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:30 leadSpacing:10 tailSpacing:10]; [MASConstraintMaker *make] {make.top.equalto (150); // Set the vertical constraints for array [self.masonRyViewarray mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalto (150);  make.height.equalTo(80); }]; }Copy the code

The test results are as follows:

2, horizontal arrangement, fixed control length, control interval is uncertain

The code is as follows:

- (void)test_masonry_horizontal_fixItemWidth {// Implement the navigation level selector [self.masonryViewArray] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:10 tailSpacing:10]; [MASConstraintMaker *make] {make.top.equalto (150); // Set the vertical constraints for array [self.masonRyViewarray mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalto (150);  make.height.equalTo(80); }]; }Copy the code

The test results are as follows:

3, vertical arrangement, fixed control interval, control height variable

The code is as follows:

- (void)test_masonry_vertical_fixSpace {// Implement the navigation vertical fixed height method. MasonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:30 leadSpacing:10 tailSpacing:10]; [MASConstraintMaker *make] {make.left. EqualTo (150); // Set the horizontal constraints for the array [self.masonRyViewarray mas_makeConstraints:^(MASConstraintMaker *make) {make.left.  make.width.equalTo(80); }]; }Copy the code

The results are as follows:

4, vertical arrangement, fixed control height, control interval is uncertain

- (void)test_masonry_vertical_fixItemWidth {// Implement the navigation vertical control height [self.masonryViewarray] mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedItemLength:80 leadSpacing:10 tailSpacing:10]; [MASConstraintMaker *make] {make.left. EqualTo (150); // Set the horizontal constraints for the array [self.masonRyViewarray mas_makeConstraints:^(MASConstraintMaker *make) {make.left.  make.width.equalTo(80); }]; }Copy the code

The results are as follows:

Third, the completion of

Recently more lazy, write a blog to refresh, find a feeling, this big good youth ah! Don’t waste it! I this Bohemian love freedom, how $%^&@*&^ %!