zoukankan      html  css  js  c++  java
  • 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来进行排列

     

  • 相关阅读:
    入门MyBatis框架你一点都不需要慌
    手把手教你玩转Git
    小米商城项目(JSP+Servlet项目)
    超详细Maven技术应用指南
    如何深入理解关系型数据库的三大范式
    MySQL触发器的详细教学与实战分析
    cute-cnblogs 番外篇-自定义博客园样式美化
    2019以终为始,不迷茫的2020 | 前端小菜鸡的年度总结~
    可爱的博客园样式之自定义“评论区”样式
    Vue中使用key的作用
  • 原文地址:https://www.cnblogs.com/rollrock/p/5195318.html
Copyright © 2011-2022 走看看