• 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
  • 相关阅读:
    jQuery使用经验建议
    java的各种类型转换汇总
    二路归并排序算法实现-完整C语言程序
    Java连接MYSQL 数据库的连接步骤
    二叉树
    bat命令批量创建文件夹
    【转】Android原生PDF功能实现
    【转】Android root检测方法总结
    【转】Android 破解视频App去除广告功能详解及解决办法总结
    【转】什么是微信62数据,62数据脚本有什么用?
  • 原文地址:https://www.cnblogs.com/igeniuswwh/p/6209139.html
Copyright © 2020-2023  润新知