首页 > 其他 > 详细

Autolayout(自动布局)

时间:2014-09-22 00:17:42      阅读:221      评论:0      收藏:0      [点我收藏+]

VFL语言实现以下界面:

bubuko.com,布布扣

- (void)viewDidLoad

{

    [super viewDidLoad];

    //创建上面的view

    UIView *topView = [[UIView alloc]init];

    topView.backgroundColor = [UIColor redColor];

    [self.view addSubview:topView];

    topView.translatesAutoresizingMaskIntoConstraints = NO;

    //创建下面的view

    UIView *bottomView = [[UIView alloc]init];

    bottomView.backgroundColor = [UIColor blueColor];

    [self.view addSubview:bottomView];

    bottomView.translatesAutoresizingMaskIntoConstraints = NO;

    //利用VFL语言

    //创建约束(垂直方向)

    NSInteger gap = 20;

    NSArray *verticalC = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-gap-[topView(==50)]-gap-[bottomView(==topView)]" options:NSLayoutFormatAlignAllRight metrics:@{@"gap":@(gap)} views:@{@"topView":topView,@"bottomView":bottomView}];

    [self.view addConstraints:verticalC];

    NSArray *herizonTopC = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-gap-[topView]-gap-|" options:NSLayoutFormatAlignAllRight metrics:@{@"gap":@(gap)} views:@{@"topView":topView}];

    [self.view addConstraints:herizonTopC];

    NSLayoutConstraint *contraintBottom = [NSLayoutConstraint constraintWithItem:bottomView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0];

    [self.view addConstraint:contraintBottom];

}

Autolayout(自动布局)

原文:http://www.cnblogs.com/bluceZ/p/3985149.html

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