码迷,mamicode.com
首页 > 其他好文 > 详细

NSLayoutConstraint的简单应用

时间:2015-12-22 01:16:53      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = [UIColor redColor];
    [self.view addSubview:topView];
    topView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addConstraints:@[
                                
                                [NSLayoutConstraint constraintWithItem:topView
                                                             attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10],
                                [NSLayoutConstraint constraintWithItem:topView
                                                             attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-10],
                                [NSLayoutConstraint constraintWithItem:topView
                                                             attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100],
                                [NSLayoutConstraint constraintWithItem:topView
                                                             attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20]
                                ]];

 

 topView在父视图的左边间距10,下边间距-10,宽度为100,高度为20的实现代码

技术分享

NSLayoutConstraint的简单应用

标签:

原文地址:http://www.cnblogs.com/salam/p/5065377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!