github地址:https://github.com/mamaral/Neon

居中

设置 view 在 superview 的中心,调用 anchorInCenter()并设置view大小,相当于frame center

 view1.anchorInCenter(width: 300, height: 300)
imgV.anchorInCenter(width: 150, height: 150)

# 填充
如果想 view 填充superview,设置距离superview的边框距离, 调用 fillSuperview()
```
imgV.fillSuperview()
imgV.fillSuperview(left: 20, right: 5, top: 30, bottom: 5)
```
![屏幕快照 2019-03-18 下午5.56.50.png](https://upload-images.jianshu.io/upload_images/7787328-8ac56cccd11053be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 角对齐
view 相对于 superview 固定于某个角,调用anchorInCorner(),并传入要对齐哪个角的参数
```
view1.anchorInCorner(.topLeft, xPad: 20, yPad: 100, width: 100, height: 100)
view2.anchorInCorner(.topRight, xPad: 20, yPad: 50, width: 100, height: 100)
view3.anchorInCorner(.bottomLeft, xPad: 20, yPad: 20, width: 100, height: 100)
view4.anchorInCorner(.bottomRight, xPad: 20, yPad: 30, width: 100, height: 100)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.01.17.png](https://upload-images.jianshu.io/upload_images/7787328-7c0e7991174be47d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 边对齐
如果想让 view 相对于 superview 的某一边依靠对齐,调用anchorToEdge,自动居中对齐
```
view1.anchorToEdge(.top, padding: 300, width: 100, height: 100)
view2.anchorToEdge(.left, padding: 0, width: 100, height: 100)
view3.anchorToEdge(.bottom, padding: 88, width: 100, height: 100)
view4.anchorToEdge(.right, padding: 0, width: 100, height: 100)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.04.10.png](https://upload-images.jianshu.io/upload_images/7787328-a182f5bd1905126b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 边填充
如果想让 view 相对于 superview 的某一边居中对齐并自动填拉伸充,调用anchorAndFillEdge()
```
view1.anchorAndFillEdge(.top, xPad: size + 5, yPad: 88, otherSize: size)
view2.anchorAndFillEdge(.bottom, xPad: size + 5, yPad: 83, otherSize: size)
view3.anchorAndFillEdge(.left, xPad: 0, yPad: 0, otherSize: size)
view4.anchorAndFillEdge(.right, xPad: 0, yPad: 0, otherSize: size)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.08.44.png](https://upload-images.jianshu.io/upload_images/7787328-0777f3fbb5622247.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 相对对齐
##### 距离相对view右边 居 上-中-下
```
view1.anchorInCenter(width: 200, height: 200)
view2.align(.toTheRightMatchingTop, relativeTo: view1, padding: 5, width: 50, height: 50)
view3.align(.toTheRightMatchingBottom, relativeTo: view1, padding: 5, width: 50, height: 50)
view4.align(.toTheRightCentered, relativeTo: view1, padding: 5, width: 50, height: 50)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.14.20.png](https://upload-images.jianshu.io/upload_images/7787328-a1cbb1692946a3cd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##### 距离相对view左边 居 上 中 下
```
view2.align(.toTheLeftMatchingTop, relativeTo: view1, padding: 5, width: 50, height: 50)
view3.align(.toTheLeftMatchingBottom, relativeTo: view1, padding: 5, width: 50, height: 50)
view4.align(.toTheLeftCentered, relativeTo: view1, padding: 5, width: 50, height: 50)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.15.48.png](https://upload-images.jianshu.io/upload_images/7787328-cef670c1d98302a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##### 距离相对view下边 居 上 中 下
```
view2.align(.underMatchingLeft, relativeTo: view1, padding: 5, width: 50, height: 50)
view3.align(.underMatchingRight, relativeTo: view1, padding: 5, width: 50, height: 50)
view4.align(.underCentered, relativeTo: view1, padding: 5, width: 50, height: 50)
```

##### 距离相对view上边 居 上 中 下
```
view2.align(.aboveMatchingLeft, relativeTo: view1, padding: 5, width: 50, height: 50)
view3.align(.aboveMatchingRight, relativeTo: view1, padding: 5, width: 50, height: 50)
view4.align(.aboveCentered, relativeTo: view1, padding: 5, width: 50, height: 50)
```

# 对齐并填充
不知道或者没法指定一个相对视图的大小,但又要兼顾填充和对齐,并且还依赖与相邻的 view。调用alignAndFill()、alignAndFillWidth()、alignAndFillHeight()
```
view1.anchorInCenter(width: 200, height: 200)
view2.alignAndFillWidth(align: .toTheRightMatchingTop, relativeTo: view1, padding: 5, height: 30)
view3.alignAndFillHeight(align: .aboveCentered, relativeTo: view1, padding: 50, width: 60)
view4.alignAndFill(align: .toTheLeftMatchingTop, relativeTo: view1, padding: 5)
```
![Simulator Screen Shot - iPhone XS Max - 2019-03-18 at 18.27.19.png](https://upload-images.jianshu.io/upload_images/7787328-c02c64834dd276a9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

# 挤压对齐
如果两个 view 夹着中间一个 view 的需求,调用alignBetweenHorizontal()和alignBetweenVertical()

view1.anchorInCenter(width: 150, height: 300)
view2.align(.toTheRightMatchingTop, relativeTo: view1, padding: 5, width: 100, height: 100)
view3.align(.toTheRightMatchingBottom, relativeTo: view1, padding: 5, width: 100, height: 100)
view4.align(.toTheRightCentered, relativeTo: view1, padding: 5, width: 100, height: 100)
view4.alignBetweenVertical(align: .aboveMatchingRight, primaryView: view3, secondaryView: view2, padding: 10, width: 50)

# 组合
多个view一起组合布局,调用groupInCenter()、groupInCorner()、groupAgainstEdge()

##### 居中对齐组合
```
view.groupInCenter(group: .vertical, views: [view1,view2,view3], padding: 10, width: size, height: size)
view.groupInCenter(group: .horizontal, views: [view1,view2,view3], padding: 20, width: size, height: size)
```
![屏幕快照 2019-03-19 上午11.26.05.png](https://upload-images.jianshu.io/upload_images/7787328-e30dccfafbb60d42.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

##### 角对齐组合 相对于superview某一个角组合排布
```
view.groupInCorner(group: .horizontal, views: [view1, view2, view3], inCorner: .bottomLeft, padding: 10, width: size, height: size)
view.groupInCorner(group: .vertical, views: [view1, view2, view3], inCorner: .bottomRight, padding: 10, width: size, height: size)

![屏幕快照 2019-03-19 上午11.28.49.png](https://upload-images.jianshu.io/upload_images/7787328-02cdb30aa15e04c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
<br/>
##### 边对齐组合,相对于superview某一条边的中点排布

view.groupAgainstEdge(group: .horizontal, views: [view1, view2, view3], againstEdge: .left, padding: 10, width: size, height: size)

view.groupAgainstEdge(group: .vertical, views: [view1, view2, view3], againstEdge: .bottom, padding: 10, width: size, height: size)

![Simulator Screen Shot - iPhone XS Max - 2019-03-19 at 11.34.19.png](https://upload-images.jianshu.io/upload_images/7787328-c60dde25111f0881.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![0FC4A788F2D326B5CFD19EDB76E96ADE.jpg](https://upload-images.jianshu.io/upload_images/7787328-596241b81f97af1f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

第三方布局框架Neon初探的更多相关文章

  1. [Swift通天遁地]六、智能布局-(8)布局框架的使用:多分辨率适配和横竖屏布局

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. iOS常用第三方开源框架和优秀开发者博客等

    博客收藏iOS开发过程好的开源框架.开源项目.Xcode工具插件.Mac软件.文章等,会不断更新维护,希望对你们有帮助.如果有推荐或者建议,请到此处提交推荐或者联系我. 该文档已提交GitHub,点击 ...

  3. Masonry 轻量级布局框架的使用

    iOS 提供了自动布局的方法,但是原生的方法使用太过麻烦 ,Masonry 框架提供了类似的方法,同样可以实现自动布局 ,代码更加直观,而且容易理解. Masonry 是一个轻量级的布局框架.拥有自己 ...

  4. Android的SwipeToDismiss第三方开源框架模拟QQ对话列表侧滑删除,置顶,将头像图片圆形化处理。

      <Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(github ...

  5. 第三方开源框架的下拉刷新列表(QQ比较常用的)。

    PullToRefreshListView是第三方开源框架下拉刷新列表,比较流行的QQ 微信等上面都在用. 下载地址(此开源框架于2013年后不再更新) 点此下载 package com.lixu.k ...

  6. iOS基础 - 第三方网络框架

    一.iOS网络层次结构 基于iOS提供API实现上传文件和断点续传的思路 常用iOS第三方网路框架简介 AFNetworking(AFN) ASIHTTPRequest(ASI) 另外一个常用框架 S ...

  7. Masonry布局框架的使用

    Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布局 简洁明了 并具有高可读性.比我们使用自动布局,繁琐的约束条件,好用多了.下面我们来学学masonry的使用方 ...

  8. IOS控件布局之Masonry布局框架

    前言: 回想起2013年做iOS开发的时候,那时候并没有采用手写布局代码的方式,而是采用xib文件来编写,如果使用纯代码方式是基于window的size(320,480)计算出一个相对位置进行布局,那 ...

  9. iOS下的界面布局利器-MyLayout布局框架

      Swift:TangramKit: https://github.com/youngsoft/TangramKit OC:MyLayout: https://github.com/youngsof ...

随机推荐

  1. HDU-1028 Ignatius and the Princess III(生成函数)

    题意 给出$n$,问用$1$到$n$的数字问能构成$n$的方案数 思路 生成函数基础题,$x^{n}$的系数即答案. 代码 #include <bits/stdc++.h> #define ...

  2. mint-ui Picker设置指定初始值

    最近做的项目公司需求是信息输入页设置地址跳转下一页后,再返回信息输入页查看信息时,地址要默认显示前面选择的地址,以此记录下,需要小伙伴可以看看 data{return{}}中设置   :slots 在 ...

  3. windows安装解压版mysql

    记录下用批处理安装mysql5.7.18的过程与踩到的坑 先在安装目录新建文件my.ini [mysql] default-character-set=utf8 basedir=TODO datadi ...

  4. WEB部分题目writeup

    MEIZIJIU_PHP 题目链接: http://202.112.51.184:20001/ 打开网页出现一段PHP代码: 代码大意就是如果得到的code不为空则执行下列操作: 如果code长度大于 ...

  5. layui table 内容为select隐藏问题

    <style> .layui-table-cell,.layui-form,.layui-table-box,.layui-table-body{ overflow: visible; } ...

  6. html注意事项

    行级元素只能嵌套行级元素 块级元素可以嵌套任何元素 格力  p标签不能嵌套div a标签不能嵌套a标签

  7. js性能的进阶

    为了说明js性能方面的差异用一个简单的例子说明下, <style> #ul1{ padding: 5px; overflow: hidden; } #ul1 li{ list-style: ...

  8. P2419 [USACO08JAN]牛大赛Cow Contest(dfs走天下/)

    题目描述 FJ的N(1 <= N <= 100)头奶牛们最近参加了场程序设计竞赛:).在赛场上,奶牛们按1..N依次编号.每头奶牛的编程能力不尽相同,并且没有哪两头奶牛的水平不相上下,也就 ...

  9. js replace替换字符串,同时替换多个方法

    在实际开发中,经常会遇到替换字符串的情况,但是大多数情况都是用replace替换一种字符串,本文介绍了如何使用replace替换多种指定的字符串,同时支持可拓展增加字符串关键字. let conten ...

  10. 逻辑卷管理(linux)

    (创建分区)1.fdisk /dev/sdb2.n3default4.default5.+200M6.w7.partprobe(更新分区)8mkfs.ext4 /dev/sdb1//格式化sdb1.. ...