zoukankan      html  css  js  c++  java
  • Autolayout(自动布局)

    VFL语言实现以下界面:

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        //创建上面的view

        UIView *topView = [[UIView alloc]init];

        topView.backgroundColor = [UIColor redColor];

        [self.view addSubview:topView];

        topView.translatesAutoresizingMaskIntoConstraints = NO;

        //创建下面的view

        UIView *bottomView = [[UIView alloc]init];

        bottomView.backgroundColor = [UIColor blueColor];

        [self.view addSubview:bottomView];

        bottomView.translatesAutoresizingMaskIntoConstraints = NO;

        //利用VFL语言

        //创建约束(垂直方向)

        NSInteger gap = 20;

        NSArray *verticalC = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-gap-[topView(==50)]-gap-[bottomView(==topView)]" options:NSLayoutFormatAlignAllRight metrics:@{@"gap":@(gap)} views:@{@"topView":topView,@"bottomView":bottomView}];

        [self.view addConstraints:verticalC];

        NSArray *herizonTopC = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-gap-[topView]-gap-|" options:NSLayoutFormatAlignAllRight metrics:@{@"gap":@(gap)} views:@{@"topView":topView}];

        [self.view addConstraints:herizonTopC];

        NSLayoutConstraint *contraintBottom = [NSLayoutConstraint constraintWithItem:bottomView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0];

        [self.view addConstraint:contraintBottom];

    }

  • 相关阅读:
    css样式2 布局 定位 层级 显示
    css与样式
    表单属性、键值对
    表单
    列表、表格
    实体、颜色、路径、标签、超链接、图片
    2018/07/05 html基础
    TP 链接数据库与Model模型的创建
    ThinkPHP 模板循环语法
    tp 单字母函数详解(摘自网络)
  • 原文地址:https://www.cnblogs.com/bluceZ/p/3985149.html
Copyright © 2011-2022 走看看