Masonry布局四設置寬高比例

屏幕快照 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);
        //設置優(yōu)先級
        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

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容