你的位置:首页 > 操作系统

[操作系统]iOS使用masonry快速将一组view在superview中等宽排列


 

 

keycode:

/** * 将若干view等宽布局于容器containerView中 * * @param views     viewArray * @param containerView 容器view * @param LRpadding   距容器的左右边距 * @param viewPadding  各view的左右边距 */-(void)makeEqualWidthViews:(NSArray *)views inView:(UIView *)containerView LRpadding:(CGFloat)LRpadding viewPadding :(CGFloat)viewPadding{  UIView *lastView;  for (UIView *view in views) {    [containerView addSubview:view];    if (lastView) {      [view mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.bottom.equalTo(containerView);        make.left.equalTo(lastView.mas_right).offset(viewPadding);        make.width.equalTo(lastView);      }];    }else    {      [view mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.equalTo(containerView).offset(LRpadding);        make.top.bottom.equalTo(containerView);      }];    }    lastView=view;  }  [lastView mas_makeConstraints:^(MASConstraintMaker *make) {    make.right.equalTo(containerView).offset(-LRpadding);  }];}