Autolayout-VFL语言

H : [ cancelButton (72)]-12-[ acceptButton (50)]
canelButton 72 acceptButton 50 ,它们之间间距 12

H : [ wideView (>=60@700)]
wideView 宽度大于等于 60point ,该约束条件优先级为 700 (优先级最大值为 1000 ,优先级越高的约束越先被满足)

V :[ redBox ]-[ yellowBox (== redBox )]
竖直 方向上 ,先 一个 redBox ,其下方紧接一个 高度 等于 redBox 高度 yellowBox

H :|- 10- [Find]-[ FindNext ]-[ FindField (>=20)]-|
水平 方向上 Find 距离父 view 左边缘默认间隔宽度,之后是 FindNext 距离 Find 间隔默认宽度;再之后是宽度不小于 20 FindField ,它和 FindNext 以及父 view 右边缘的间距都是默认宽度。( 竖线“ | 表示 superview 的边缘)




 // 1.添加控件

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

    blueView.backgroundColor = [UIColor blueColor];

    blueView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addSubview:blueView];

    

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

    redView.backgroundColor = [UIColor redColor];

    redView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addSubview:redView];

    

    // 2.VFL生成约束

    NSArray *conts = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[blueView]-20-|" options:0 metrics:nil views:@{@"blueView" : blueView}];

    [self.view addConstraints:conts];

    

    NSArray *conts2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[blueView(40)]-20-[redView(==blueView)]" options:NSLayoutFormatAlignAllRight metrics:nil views:@{@"blueView" : blueView, @"redView" : redView}];

    [self.view addConstraints:conts2];

    

    NSLayoutConstraint *redWidth = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0.0];

    [self.view addConstraint:redWidth];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值