Masonry布局四设置宽高比例

Masonry布局四设置宽高比例_第1张图片
屏幕快照 2016-12-05 下午2.07.57.png
//
//  ThrViewController.m
//  MasonrySecond
//
//  Created by mibo02 on 16/12/5.
//  Copyright © 2016年 mibo02. All rights reserved.
//

#import "ThrViewController.h"
#import "Masonry.h"
@interface ThrViewController ()

@end

@implementation ThrViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor redColor];
    [self.view addSubview:topView];
    UIView *topInnerView = [UIView new];
    topInnerView.backgroundColor = [UIColor greenColor];
    [topView addSubview:topInnerView];
    
    //设置约束
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(100);
        
        
    }];
    
    [topInnerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(topView);
//        make.width.mas_equalTo(topView);
//        make.height.mas_equalTo(topView.mas_height).multipliedBy(0.5);
        //设置宽高比例为7:1
        make.width.mas_equalTo(topInnerView.mas_height).multipliedBy(7);
        make.center.mas_equalTo(topView);
        //设置优先级
        make.width.height.mas_equalTo(topView).priorityLow();
        make.width.height.lessThanOrEqualTo(topView);
    }];
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

你可能感兴趣的:(Masonry布局四设置宽高比例)