zoukankan      html  css  js  c++  java
  • Masonry(第三方库)的使—代码实现屏幕适配

    #import"Masonry"

    实现效果图

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        [self testBasicLayout];
        [self testThreeLayout];
    }
    - (void)testThreeLayout
    {
        UIView *redView = [[UIView alloc] init];
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
        
        UIView *blueView = [[UIView alloc] init];
        blueView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:blueView];
        
        UIView *greenView = [[UIView alloc] init];
        greenView.backgroundColor = [UIColor greenColor];
        [self.view addSubview:greenView];
        
        [redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(50);
            make.left.mas_equalTo(50);
            make.right.mas_equalTo(-50);
            make.height.mas_equalTo(100);
        }];
        [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(redView.mas_bottom).offset(50);//偏移量 默认0
            make.left.mas_equalTo(50);
            make.height.mas_equalTo(100);
            //make.width.mas_equalTo(100);
        }];
        [greenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(redView.mas_bottom).offset(50);
            make.right.mas_equalTo(-50);
            make.height.mas_equalTo(100);
            make.width.mas_equalTo(100);
            
            //间隔固定,宽度相等
            make.left.mas_equalTo(blueView.mas_right).offset(50);
            make.width.mas_equalTo(blueView.mas_width);
        }];
    }
    - (void)testBasicLayout
    {
        //靠右对齐,100x100,top-50 right-50
        UIView *redView = [[UIView alloc] init];
        redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:redView];
        //block重要参数:mark参数,设置make的属性。控制布局
        /*
        [redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(100);
            make.top.mas_equalTo(50);
            make.right.mas_equalTo(-50);
            
        }];
         */
        [redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(50);
            make.left.mas_equalTo(50);
            make.right.mas_equalTo(-50);
            make.height.mas_equalTo(100);
        }];
    }
    View Code
  • 相关阅读:
    单例模式
    自旋锁与互斥锁
    CAS无锁机制原理
    乐观锁和悲观锁
    读写锁
    Java锁机制-重入锁
    原 Linux搭建SVN 服务器2
    原 Linux搭建SVN 服务器
    Sublime Text 3 破解版 + 注册机 + 汉化包 + 教程
    Sublime Text 3 常用插件以及安装方法(转)
  • 原文地址:https://www.cnblogs.com/caolongs/p/4774113.html
Copyright © 2011-2022 走看看