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

    }

  • 相关阅读:
    IBM Tivoli Netview在企业网络管理中的实践(附视频)
    应用Linux远程桌面(附视频)
    轻松八步搞定Cacti配置安装(原创视频)
    从程序详解拒绝服务攻击
    基于Linux平台的Openvas配置使用视频教学
    Sco Unixware 7.1.3企业版服务器安装视频教程
    P1305-新二叉树
    P1087-FBI树
    P1115-最大子段和
    P1996-约瑟夫问题
  • 原文地址:https://www.cnblogs.com/bluceZ/p/3985149.html
Copyright © 2011-2022 走看看