zoukankan      html  css  js  c++  java
  • Masonry应用【美图秀秀首页界面自动布局】

      Masonry在此实现时候,并没有比NSLayoutConstraint简单,相反我觉得还不如NSLayoutConstraint。

        [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top);
            make.right.equalTo(self.view.mas_right).with.offset(-6);
            make.width.equalTo(@51);
            make.height.equalTo(@61);
        }];
        
        [btnSetting mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view.mas_bottom).with.offset(-8);
            make.right.equalTo(self.view.mas_right).with.offset(-6);
            make.width.equalTo(@39);
            make.height.equalTo(btnSetting.mas_width);
        }];
        
        [self.scrolleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(image.mas_bottom);
            make.left.equalTo(self.view.mas_left);
            make.width.equalTo(@(WIDTH-0));
            make.height.equalTo(@(HEIGHT - 47 - 61));
        }];

    下面是使用NSLayoutConstraint的代码实现

                                    [NSLayoutConstraint constraintWithItem:self.topView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0],
                                    [NSLayoutConstraint constraintWithItem:self.topView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-6],
                                    [NSLayoutConstraint constraintWithItem:self.topView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:51],
                                    [NSLayoutConstraint constraintWithItem:self.topView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:61],
                                    
                                    [NSLayoutConstraint constraintWithItem:btnSetting attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-8],
                                    [NSLayoutConstraint constraintWithItem:btnSetting attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:-6],
                                    [NSLayoutConstraint constraintWithItem:btnSetting attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:39],
                                    [NSLayoutConstraint constraintWithItem:btnSetting attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:btnSetting attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0],
                                    
                                    [NSLayoutConstraint constraintWithItem:self.scrolleView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:image attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0],
                                    [NSLayoutConstraint constraintWithItem:self.scrolleView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0],
                                    [NSLayoutConstraint constraintWithItem:self.scrolleView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:WIDTH],
                                    [NSLayoutConstraint constraintWithItem:self.scrolleView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:HEIGHT - 47 - 61]

    至于使用哪种布局库,自行斟酌。。。。

  • 相关阅读:
    SpringMVC自动封装List对象 —— 自定义参数解析器
    fetch封装
    基于jQuery实现简单的js模块化
    CSS实现树形结构 + js加载数据
    java多线程
    JS中AOP的实现和运用
    移动端通过ajax上传图片(文件)并在前台展示——通过H5的FormData对象
    chart.js使用常见问题
    用PHP和Ajax进行前后台数据交互——以用户登录为例
    用JS添加和删除class类名
  • 原文地址:https://www.cnblogs.com/salam/p/5074706.html
Copyright © 2011-2022 走看看