美文网首页
masonry 九宫格

masonry 九宫格

作者: gushidekaitou | 来源:发表于2017-08-07 21:53 被阅读6次
  1. 固定宽高,以及间距的情况
- (void)confUI
{
    CGFloat w = (ScreenWidth -24)/3;
    UIView *bgview = [[UIView alloc]init];
    [self addSubview:bgview];
    bgview.layer.borderColor = [UIColor blackColor].CGColor;
    bgview.layer.borderWidth = 1.0;
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.right.left.equalTo(self);
    }];
    
    
    UIView *lastView = nil;
    for (NSInteger i = 0; i<9; i++) {
        UIView *view = [[ UIView alloc]init];
        [bgview addSubview:view];
        view.backgroundColor = [UIColor colorWithHue:(arc4random() % 256 / 256.0 ) saturation:( arc4random() % 128 / 256.0 ) + 0.5
                                          brightness:( arc4random() % 128 / 256.0 ) + 0.5 alpha:1.0];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            if (i%3 == 0) {
                if (lastView) {
                    make.top.equalTo(lastView.mas_bottom).offset(6);
                }else{
                    make.top.equalTo(bgview).offset(6);
                }
                make.left.equalTo(bgview).offset(6);
            }else if (i%3 == 1)
            {
                make.left.equalTo(lastView.mas_right).offset(6);
                make.top.equalTo(lastView.mas_top);
            }else{
                make.left.equalTo(lastView.mas_right).offset(6);
                make.right.equalTo(bgview.mas_right).offset(-6);
                make.top.equalTo(lastView.mas_top);
            }
            make.height.equalTo(@(w));
            make.width.equalTo(@(w));
        }];
        lastView = view;
    }
    [lastView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgview.mas_bottom);
    }];

}

相关文章

  • iOS masonry九宫格 单行 多行布局

    iOS masonry九宫格 单行 多行布局 Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关...

  • OC_九宫格布局工具

    实现基于: iOS Masonry九宫格布局 - 一行代码实现九宫格 demo点这里 以后你可能会这样布局九宫格 ...

  • 2015.10.12

    1.使用collectionview创建了九宫格布局 2.使用masonry进行自适应布局。 3.学习了50个英文...

  • masonry 九宫格

    固定宽高,以及间距的情况

  • Masonry布局九宫格

    这个是结合别人代码和自己需求的代码。可以满足日常使用1、布局代码 2、示例代码 3、效果图

  • Masonry 介绍 2018-01-29

    介绍 Masonry 源码:https://github.com/Masonry/Masonry Masonry是...

  • 关于Masonry小记

    Masonry 源码:https://github.com/Masonry/Masonry Masonry是一个轻...

  • Masonry的用法

    Masonry 源码:https://github.com/Masonry/Masonry; 看一下Masonry...

  • Masonry实现简单动画

    1.安装Masonry库pod 'Masonry' 2.导入Masonry import

  • Masonry 九宫格方式排列

    今天项目有用到九宫格方式排列,就记录一下。 代码如下: 希望对新手朋友有点帮助,有问题可以留言。

网友评论

      本文标题:masonry 九宫格

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