首页 > 移动平台 > 详细

iOS原生的布局写法

时间:2015-12-08 18:23:59      阅读:403      评论:0      收藏:0      [点我收藏+]

方法1:使用 HV方式

self.backImageView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[backimage]-|" options:NSLayoutFormatAlignmentMask metrics:nil views:@{@"backimage":self.backImageView}]];

     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[backimage]-|" options:NSLayoutFormatAlignmentMask metrics:nil views:@{@"backimage":self.backImageView}]];

 

//直接加

    self.phoneView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.phoneView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.logoImage attribute:NSLayoutAttributeBottom multiplier:1.0 constant:33 * FitHeight]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.phoneView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.phoneView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1.0 constant:230 * FitWidth]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.phoneView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:42 * FitHeight]];

 

采用 masorny 的写法

//电话框

    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {

       

        make.top.equalTo(self.logoImage.mas_bottom).offset(33 * FitHeight);

        make.centerX.equalTo(self.view.mas_centerX);

        make.width.equalTo(@(230 * FitWidth));

        make.height.equalTo(@(42 * FitHeight));

    }];

 

iOS原生的布局写法

原文:http://www.cnblogs.com/aiyiran/p/5029794.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!