IOS autoLayout之使用VFL语言进行代码自动布局

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的边缘)
eg: 
// 代码方式实现自动布局VFL
    // 创建一个Tableview;
    UITableView *tableView = [[UITableViewalloc]init];
    tableView.backgroundColor = [UIColorredColor];

#warning 代码实现自动布局,要设置下面的属性为NO    tableView.translatesAutoresizingMaskIntoConstraints =NO;
    [self.viewaddSubview:tableView];
   
    // 创建输入框View
    WCInputView *inputView = [WCInputViewinputView];
    inputView.translatesAutoresizingMaskIntoConstraints =NO;
    [self.viewaddSubview:inputView];
   
    // 自动布局
   
    // 水平方向的约束
   NSDictionary *views = @{@"tableview":tableView,
                            @"inputView":inputView};
   
    // 1.tabview水平方向的约束
    NSArray *tabviewHConstraints = [NSLayoutConstraintconstraintsWithVisualFormat:@"H:|-0-[tableview]-0-|"options:0metrics:nilviews:views];
    [self.viewaddConstraints:tabviewHConstraints];
   
    // 2.inputView水平方向的约束
    NSArray *inputViewHConstraints = [NSLayoutConstraintconstraintsWithVisualFormat:@"H:|-0-[inputView]-0-|"options:0metrics:nilviews:views];
    [self.viewaddConstraints:inputViewHConstraints];



    // 注意: 在VFL语句中, 是不支持乘除法
//    NSArray *redVeiwH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[redView(==blueView / 2 )]" options:0 metrics:nil views:@{@"blueView" : blueView, @"redView": redView}];
//    [self.view addConstraints:redVeiwH];
// 要结合下面的方法才能执行
    NSLayoutConstraint *redVeiwW = [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:blueView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0];
    [self.view addConstraint:redVeiwW];
具体参数如下:(storyBoard里面的约束)


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值