zoukankan      html  css  js  c++  java
  • ios 关于VFL的一点事情

    VFL :Visual Format language

    写法:

    功能        表达式

    水平方向          H:

    垂直方向          V:

    Views         [view]

    SuperView      |

    关系         >=,==,<=

    空间,间隙       -

    优先级        @value

     

    需要注意的是,在用代码创建的UIView在,一定要加上下面这句代码

       XXX.translatesAutoresizingMaskIntoConstraints=NO;

    如果没有上面这一行,你的约束将不生效,控制台会输出一连串的错误.

     


    具体上代码:

     

        // 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生成约束

        NSDictionary *mertrics = @{@"margin" : @20}; // 参数数值

        NSDictionary *views = NSDictionaryOfVariableBindings(blueView, redView);

        NSArray *conts = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-margin-[blueView]-margin-[redView(==blueView)]-margin-|" options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:mertrics views:views];

        

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

        [self.view addConstraints:conts];

        [self.view addConstraints:conts2];

     

     

        UIButton *button=[[UIButton alloc]init];

        button=[UIButton buttonWithType:UIButtonTypeSystem];

        [button setTitle:@"VFL" forState:UIControlStateNormal];

        button.translatesAutoresizingMaskIntoConstraints=NO;

        [button setBackgroundColor:[UIColor blackColor]];

        [self.view addSubview:button];

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

        NSArray *Vconstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-300-[button]-200-|" options:0 metrics:nil views:@{@"button":button}];

        [self.view addConstraints:Hconstraint];

        [self.view addConstraints:Vconstraint];

     

     

  • 相关阅读:
    python语法基础-并发编程-协程-长期维护
    python语法基础-并发编程-线程-其他
    python语法基础-并发编程-线程-线程池
    python语法基础-并发编程-线程-各种锁以及队列
    python语法基础-并发编程-线程-线程理论和线程的启动
    python语法基础-并发编程-进程-其他
    python语法基础-并发编程-进程-进程池以及回调函数
    python语法基础-并发编程-进程-进程锁和进程间通信
    python语法基础-并发编程-进程-进程理论和进程的开启
    二、提高期(Upping the Ante)
  • 原文地址:https://www.cnblogs.com/allenChan/p/4335068.html
Copyright © 2011-2022 走看看