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来进行排列

     

  • 相关阅读:
    Python 基础之 线程与进程
    python 基础之 模块
    Python 基础之socket编程(三)
    Python 基础之socket编程(二)
    Python全栈开发之11、进程和线程
    用 Python实现一个ftp+CRT(不用ftplib)
    Python全栈开发之10、网络编程
    Python全栈开发之9、面向对象、元类以及单例
    Python全栈开发之8、装饰器详解
    用python实现一个无界面的2048
  • 原文地址:https://www.cnblogs.com/rollrock/p/5195318.html
Copyright © 2011-2022 走看看