VFL语言

VFL语言

  • VFL即Visual Format Language,可视化格式语言
  • NSDictionaryOfVariableBindings(testViewA, testViewB):此为一个宏,直接调用,会返回一个key值即为对象名称,键值为对象的字典,如同以下方法一一模一样的字典
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *testViewA = [[UIView alloc] init];
    testViewA.backgroundColor = [UIColor blueColor];
    //将testViewA的AutoresizingMask自动转化成约束的属性关闭
    testViewA.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:testViewA];
    
    UIView *testViewB = [[UIView alloc] init];
    testViewB.backgroundColor = [UIColor redColor];
    //将testViewB的AutoresizingMask自动转化成约束的属性关闭
    testViewB.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:testViewB];
    
    //创建参数views字典方式一
    NSDictionary *viewDict1 = @{
                          @"testViewA":testViewA,
                          @"testViewB":testViewB
                          };
    //创建参数metrics字典
    NSDictionary *constant = @{
                               @"space":@30
                               };
    //创建水平方向的约束
    NSString *hVFL = @"H:|-space-[testViewA]-space-[testViewB(==testViewA)]-space-|";
    NSArray *hConstrains = [NSLayoutConstraint constraintsWithVisualFormat:hVFL options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom  metrics:constant views:viewDict1];
    [self.view addConstraints:hConstrains];
    
    //创建参数views字典方式二
    NSDictionary *viewDict2 = NSDictionaryOfVariableBindings(testViewA, testViewB);
    //创建垂直方向的约束
    NSString *vVFL = @"V:[testViewA(50)]-space-|";
    NSArray *vConstrains = [NSLayoutConstraint constraintsWithVisualFormat:vVFL options:kNilOptions metrics:constant views:viewDict2];
    [self.view addConstraints:vConstrains];


}
@end

 

转载于:https://www.cnblogs.com/igeniuswwh/p/6209139.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值