zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    洛谷 1.5.1 Number Triangles 数字金字塔
    洛谷 Sorting a Three-Valued Sequence 三值的排序
    洛谷 Transformations 方块转换
    POJ 1401 Factorial
    Java面试那些事
    JVM字节码执行引擎
    一个工作三年左右的Java程序员和大家谈谈从业心得
    浅谈volatile关键字
    Java内存模型
    Integer 错误的加锁
  • 原文地址:https://www.cnblogs.com/igeniuswwh/p/6209139.html
Copyright © 2011-2022 走看看