美文网首页
for循环加载视图使用Masory

for循环加载视图使用Masory

作者: NiuBaBa | 来源:发表于2017-04-19 12:07 被阅读72次
        __block UIView *lastView=nil;
        int intes =SP_Floatt(10);
        int num=5;
        
        for (int i=0; i<10; i++) {
            
            UIButton *imageB=[UIButton buttonWithType:UIButtonTypeCustom];
            [imageB setImage:[UIImage imageNamed:[NSString stringWithFormat:@"1.png"]] forState:UIControlStateNormal];
            [self.view addSubview:imageB];
            [imageB mas_makeConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(SP_Floatt(80));
                if (lastView) {
                    make.width.equalTo(lastView);
                }else{
                    if (i % num!=0) {
                        make.width.mas_equalTo((weakSelf.view.frame.size.width-(num+1)*intes/11));
                    }
                }
                if (i%num==0) {
                    make.left.mas_equalTo(weakSelf.view).offset(intes);
                }else{
                    make.left.mas_equalTo(lastView.mas_right).offset(intes);
                }
                
                if (i%num==(num-1)) {
                    make.right.mas_equalTo(weakSelf.view).offset(-intes);
                }
                if (i / num == 0) {
                    make.top.mas_equalTo(xuanze.mas_bottom).offset(intes);
                } else {
                    make.top.mas_equalTo(xuanze.mas_bottom).offset(intes+80);
                }
            }];
            lastView=imageB;
        }
    

    相关文章

      网友评论

          本文标题:for循环加载视图使用Masory

          本文链接:https://www.haomeiwen.com/subject/howczttx.html