首页 > 其他 > 详细

NSLayoutConstraint的简单应用

时间:2015-12-22 01:15:30      阅读:149      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!