zoukankan      html  css  js  c++  java
  • masonry 基本用法

    一:masonry 基本用法

     
        fistView=[[UIView alloc] init];
        fistView.backgroundColor=[UIColor redColor];
        [self.view addSubview:fistView];
      
       secondView=[[UIView alloc] init];
        secondView.backgroundColor=[UIColor blueColor];
        [self.view addSubview:secondView];
        
        threeView=[[UIView alloc] init];
        threeView.backgroundColor=[UIColor yellowColor];
        [self.view addSubview:threeView];
        
        
        bottomView=[[UIView alloc] init];
        bottomView.backgroundColor=[UIColor grayColor];
        [self.view addSubview:bottomView];

    基本约束布局代码

    #pragma mark -第一种布局方法
    
    -(void)left_top_size_marign{
        
        CGFloat padding =10;
        CGFloat width=(self.view.bounds.size.width-4*padding)/3;
        
        [fistView mas_makeConstraints:^(MASConstraintMaker *make) {
        
            make.left.mas_equalTo(padding);
            make.top.mas_equalTo(padding);
            make.size.mas_equalTo(CGSizeMake(width, 100));
            
        }];
    
        [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(padding*2+width);
            make.top.mas_equalTo(padding);
            make.size.mas_equalTo(CGSizeMake(width, 100));
            
        }];
        
        
        [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(padding*3+width*2);
            make.top.mas_equalTo(padding);
            make.size.mas_equalTo(CGSizeMake(width, 100));
            
        }];
        
        
        
    }

    二:masonry 相对于子View布局

    CGFloat padding =10;
        CGFloat width=(self.view.bounds.size.width-4*padding)/3;
        
        [fistView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(padding);
            make.top.mas_equalTo(padding);
            make.size.mas_equalTo(CGSizeMake(width, 100));
        }];
    
        
        [secondView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(fistView.mas_right).offset(padding);
            make.size.top.mas_equalTo(fistView);
    
        }];
        
        [threeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(secondView.mas_right).offset(padding);
            make.size.top.mas_equalTo(secondView);
            
        }];

    三:masonry内边距布局

    //内边距
        [paddingView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.edges.equalTo(fistView).insets(UIEdgeInsetsMake(5, 5, 5, 5));
            
        }];

    四:UILable 多行布局

     lb=[[UILabel alloc] init];
        lb.text=@"ication:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add remote-notification to the list of your supported";
        [self.view addSubview:lb];
    
    
    ---------
    
    //label多行
        lb.preferredMaxLayoutWidth=self.view.width-20;
        
        lb.numberOfLines=0;
        [lb mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.top.mas_equalTo(bottomView.mas_bottom).offset(5);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
            
            
            
        }];

     五:masonry动画更新

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        
        if(flag){
            
            CGFloat padding =10;
            CGFloat width=(self.view.bounds.size.width-4*padding)/3;
            
            [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(padding);
                make.top.mas_equalTo(padding);
                make.size.mas_equalTo(CGSizeMake(width, 100));
            }];
            
            
        }
        else{
            
            [fistView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(5);
                make.top.mas_equalTo(5);
                make.size.mas_equalTo(CGSizeMake(200, 200));
            }];
        }
        
        flag=!flag;
        
        [UIView animateWithDuration:0.25 animations:^{
           
    //        [self.view layoutIfNeeded];
            
        } completion:^(BOOL finished) {
            
        }];
        
        
    }
  • 相关阅读:
    C++实现合并两个已经排序的链表
    C++实现查找链表中环的入口节点
    IOU
    梯度下降法
    ubuntu下opencv CMakeLists.txt编写
    vs2015运行时提示未加载vcruntime140.adm64.pb
    opencv图像加文字与运行时间
    github下载总是失败解决
    vs2015配置cv文件,不用每次新建项目在配置
    Microsoft visual studio 2015已停止工作最全解决办法
  • 原文地址:https://www.cnblogs.com/gcb999/p/7047727.html
Copyright © 2011-2022 走看看