注意

使用前必须先取消所有的你想设置View 的 Autoresizing 属性 因为 Autoresizing  Layout不能共存  系统默认是 Autoresizing

 for v in subviews {
v.translatesAutoresizingMaskIntoConstraints=false
}
  • 自动布局核心公式
view1.attr1 = view2.attr2 * multiplier + constant
  • 自动布局构造函数
NSLayoutConstraint(item: 视图,
attribute: 约束属性,
relatedBy: 约束关系,
toItem: 参照视图,
attribute: 参照属性,
multiplier: 乘积,
constant: 约束数值)
  • 如果指定  约束

    • 参照视图设置为 nil
    • 参照属性选择 .NotAnAttribute
  • 自动布局类函数

NSLayoutConstraint.constraintsWithVisualFormat(VLF公式,
options: [],
metrics: 约束数值字典 [String: 数值],
views: 视图字典 [String: 子视图])
  • VFL 可视化格式语言

    • H 水平方向
    • V 垂直方向
    • | 边界
    • [] 包含控件的名称字符串,对应关系在 views 字典中定义
    • () 定义控件的宽/高,可以在 metrics 中指定
  // icon布局  上下左右居中
addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerX,
relatedBy: .equal,
toItem: self,
attribute: .centerX,
multiplier: 1.0,
constant: ))
addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerY,
relatedBy: .equal,
toItem: self,
attribute: .centerY,
multiplier: 1.0,
constant: -)) maskiconView 和屏幕等宽 和屏幕顶部对齐 距离 loginBtn顶部 - 距离
let viewDic : [String : Any] = ["maskiconView":maskiconView,"loginBtn":loginBtn]
let metricDic = ["spacing":-] addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[maskiconView]-0-|",
options: [],
metrics: nil,
views: viewDic)) addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[maskiconView]-(spacing)-[loginBtn]",
options: [],
metrics: metricDic,
views: viewDic))

NSLayoutConstraint 使用详解 VFL使用介绍的更多相关文章

  1. Spring4.X + spring MVC + Mybatis3 零配置应用开发框架搭建详解(1) - 基本介绍

    Spring4.X + spring MVC + Mybatis3 零配置应用开发框架搭建详解(1) - 基本介绍 spring集成 mybatis Spring4.x零配置框架搭建 两年前一直在做后 ...

  2. NSLayoutConstraint.constraintsWithVisualFormat详解,以及AlignAllCenterY

    NSLayoutConstraint.constraintsWithVisualFormat详解,以及AlignAllCenterY 转载2015-07-08 18:02:02 鉴于苹果官方文档的解释 ...

  3. Solr系列三:solr索引详解(Schema介绍、字段定义详解、Schema API 介绍)

    一.Schema介绍 1. Schema 是什么? Schema:模式,是集合/内核中字段的定义,让solr知道集合/内核包含哪些字段.字段的数据类型.字段该索引存储. 2. Schema 的定义方式 ...

  4. Spring-data-jpa详解,全方位介绍。

    本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...

  5. C++11 并发指南六(atomic 类型详解一 atomic_flag 介绍)

    C++11 并发指南已经写了 5 章,前五章重点介绍了多线程编程方面的内容,但大部分内容只涉及多线程.互斥量.条件变量和异步编程相关的 API,C++11 程序员完全可以不必知道这些 API 在底层是 ...

  6. 【原创】纯干货,Spring-data-jpa详解,全方位介绍。

    本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...

  7. 纯干货,Spring-data-jpa详解,全方位介绍

    本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...

  8. 【转帖】C# DllImport 系统调用使用详解 托管代码的介绍 EntryPoint的使用

    1      DLLImport的使用 using System; using System.Runtime.InteropServices; //命名空间 class Example { //用Dl ...

  9. 【Android基础】Fragment 详解之Fragment介绍

    Fragment在Android 3.0( API 11)引入,是为了支持在大屏上显示更加动态.灵活的UI,比如在平板和电视上.Fragment可以看作是嵌套的Activity,类似ActivityG ...

随机推荐

  1. sqlserver 循环取时间

    declare @str date; set @str='2015-01-08'; while DATEDIFF([day], @str , '2015-02-01')>0 begin sele ...

  2. webpack学习笔记——打包js

    1.新建一个入口js文件,如entry.js,代码如下: document.write("It works.") 2.然后编译 entry.js 并打包到 bundle.js(会自 ...

  3. Spark Streaming连接Kafka的两种方式 direct 跟receiver 方式接收数据的区别

    Receiver是使用Kafka的高层次Consumer API来实现的. Receiver从Kafka中获取的数据都是存储在Spark Executor的内存中的,然后Spark Streaming ...

  4. 5.28 js基础 简介

    Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) JavaScript历史背景介绍 布 ...

  5. HttpWebResponse 解压gzip、deflate压缩

    需要使用到两个Stream的子类:GZipStream.DeflateStream,代码如下: public string GetResponseBody(HttpWebResponse respon ...

  6. call,apply和bind的区别

    call,apply继承并调用该函数,bind继承后未调用函数. var React = require('react'); //核心 var ReactDom = require('react-do ...

  7. 人人中的 shiro权限管理 简单说明

    maven  shiro包的引用路径 :C:\Users\yanfazhongxin\.m2\repository\org\apache\shiro\shiro-core\1.3.2\shiro-co ...

  8. ActiveMQ中JMS的可靠性机制

    全文用到的生产者代码: package cn.qlq.activemq; import javax.jms.Connection; import javax.jms.ConnectionFactory ...

  9. MySQL 4.1-5.0-5.1-5.5-5.6各版本的主要区别

    各版本的一些命令差异:  show innodb status\G mysql-5.1  show engines innodb status\G mysql-5.5  关于grant授权 mysql ...

  10. Tomcat 部署及配置

    下载,解压tomcat.jdk 1.解压,链接tomcat.jdk tar xf jdk-8u161-linux-x64.tar.gz .tar.gz .0_161/ /usr/local/ .0_1 ...