注意

使用前必须先取消所有的你想设置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. ThinkPHP5.0.21&5.1.* 代码执行和命令执行漏洞利用

    ThinkPHP5.0.21&5.1.* 代码执行和命令执行漏洞利用 ThinkPHP5.0.21&5.1.*  exploit code execution and command ...

  2. luogu P2520 [HAOI2011]向量

    传送门 一堆人说数论只会gcd,我连gcd都不会,菜死算了qwq Orzyyb 这题欺负我数学不好qwq 首先可以发现实际上有如下操作:x或y±2a,x或y±2b,x+a y+b,x+b y+a(后面 ...

  3. ubuntu安装GBK编码

    1 添加GBK编码 sudo vim /var/lib/locales/supported.d/local en_US.UTF-8 UTF-8 zh_CN.UTF-8 UTF-8 zh_CN.GBK ...

  4. 第27月第18天 epoll lt et

    1. While the usage of epoll when employed as a level-triggered interface does have the same semantic ...

  5. 7-10 多项式A除以B (25 分)

    题目链接:https://pintia.cn/problem-sets/1108548596745592832/problems/1108548661014913033 题目大意: 这仍然是一道关于A ...

  6. 如何在eclipse安装apk包

    如何在eclipse安装下载好的apk包 好像是有好几种方法,我成功的是这种. 1.首先启动模拟器,我选择的是Android 4.2.2,因为...默认安得Android 7.1.1起不了,真是大坑, ...

  7. Serializable 和Parcelable 的区别

    1.作用 Serializable的作用是为了保存对象的属性到本地文件.数据库.网络流.RMI(Remote Method Invocation)以方便数据传输,当然这种传输可以是程序内的也可以是两个 ...

  8. openstack Q版部署-----安装报错问题

    1.实例开机提示找不到磁盘Booting from Hard Disk... GRUB. 开启 CPU 虚拟化支持. 将计算节点 nova.conf 配置修改如下即可: [libvirt] cpu_m ...

  9. [转] python运行时内存分析工具meliae

    转自:https://my.oschina.net/markco/blog/601773 利用meliae来监控python进程的内存占用情况 meliae是一个python进程内存占用监控.分析工具 ...

  10. Iterables vs. Iterators vs. Generators

    Reprinted from: Iterables vs. Iterators vs. Generators Occasionally I've run into situations of conf ...