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];

    }

  • 相关阅读:
    Python常见的几种算法
    Python的八种数据类型
    网络协议
    Python基本知识
    Python简介
    Windows10 java环境配置
    linux 为动态分配的Virtualbox虚拟硬盘扩容
    ubuntu 18.04.1安装hadoop3.1.2
    linux 安装virtualbox5.2
    这是写给我自己看的!!
  • 原文地址:https://www.cnblogs.com/bluceZ/p/3985149.html
Copyright © 2011-2022 走看看