Masonry 固定宽度 等间距

-(void)makeEqualDisViews:(NSArray *)views inView:(UIView *)containerView LRpadding:(CGFloat)LRpadding viewWidth:(CGFloat)viewWidth

{

    UIView * lastView;

    __block NSInteger index = 0;

    

    NSMutableArray * tempViewsArray = [NSMutableArray new];

    for( int i = 0; i < views.count-1; ++ i )

    {

        UIView * v = [UIView new];

        v.backgroundColor = [UIColor blueColor];

        [containerView addSubview:v];

        [tempViewsArray addObject:v];

        

        [v mas_makeConstraints:^(MASConstraintMaker *make) {

            make.height.equalTo(@5);

            make.bottom.equalTo(containerView.mas_bottom);

        }];

        

        if( i > 0 )

        {

            [v mas_makeConstraints:^(MASConstraintMaker *make) {

                make.width.equalTo(((UIView*)[tempViewsArray objectAtIndex:0]).mas_width);

            }];

        }

    }

    

    

    

    for( UIView * view in views )

    {

        if( index >= 10 )

            break;

        

        [containerView addSubview:view];

        

        if( lastView )

        {

            [view mas_makeConstraints:^(MASConstraintMaker *make) {

               

                UIView * v = tempViewsArray[index];

                

                make.left.equalTo(v.mas_right);

                make.width.height.equalTo([NSNumber numberWithFloat:viewWidth]);

                make.centerY.equalTo(containerView);

                

                if( index < views.count-2)

                {

                    UIView * rV = tempViewsArray[index+1];

                    make.right.equalTo(rV.mas_left);

                }

                

                ++ index;

            }];

        }

        else

        {

            [view mas_makeConstraints:^(MASConstraintMaker *make) {

                make.width.height.equalTo([NSNumber numberWithFloat:viewWidth]);

                make.left.equalTo(containerView).offset(LRpadding);

                make.centerY.equalTo(containerView);

                

            }];

            

            UIView * v = tempViewsArray[0];

            [v mas_makeConstraints:^(MASConstraintMaker *make) {

               

                make.left.equalTo(view.mas_right);

            }];

        }

        

        lastView = view;

    }

    

    if( lastView )

    {

        [lastView mas_makeConstraints:^(MASConstraintMaker *make) {

           

            make.right.equalTo(containerView).offset(-LRpadding);

            

        }];

    }

}

主要是加入了辅助的价格view来进行排列

 

原文地址:https://www.cnblogs.com/rollrock/p/5195318.html