#Masonry [![Build Status](https://travis-ci.org/SnapKit/Masonry.svg?branch=master)](https://travis-ci.org/SnapKit/Masonry) [![Coverage Status](https://img.shields.io/coveralls/SnapKit/Masonry.svg?style=flat-square)](https://coveralls.io/r/SnapKit/Masonry) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Pod Version](https://img.shields.io/cocoapods/v/Masonry.svg?style=flat)
**Masonry is still actively maintained, we are committed to fixing bugs and merging good quality PRs from the wider community. However if you're using Swift in your project, we recommend using [SnapKit](https://github.com/SnapKit/SnapKit) as it provides better type safety with a simpler API.**
Masonry is a light-weight layout framework which wraps AutoLayout with a nicer syntax. Masonry has its own layout DSL which provides a chainable way of describing your NSLayoutConstraints which results in layout code that is more concise and readable.
Masonry supports iOS and Mac OS X.
For examples take a look at the **Masonry iOS Examples** project in the Masonry workspace. You will need to run `pod install` after downloading.
## What's wrong with NSLayoutConstraints?
Under the hood Auto Layout is a powerful and flexible way of organising and laying out your views. However creating constraints from code is verbose and not very descriptive.
Imagine a simple example in which you want to have a view fill its superview but inset by 10 pixels on every side
```obj-c
UIView *superview = self.view;
UIView *view1 = [[UIView alloc] init];
view1.translatesAutoresizingMaskIntoConstraints = NO;
view1.backgroundColor = [UIColor greenColor];
[superview addSubview:view1];
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[superview addConstraints:@[
//view1 constraints
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:padding.top],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:padding.left],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-padding.bottom],
[NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeRight
multiplier:1
constant:-padding.right],
]];
```
Even with such a simple example the code needed is quite verbose and quickly becomes unreadable when you have more than 2 or 3 views.
Another option is to use Visual Format Language (VFL), which is a bit less long winded.
However the ASCII type syntax has its own pitfalls and its also a bit harder to animate as `NSLayoutConstraint constraintsWithVisualFormat:` returns an array.
## Prepare to meet your Maker!
Heres the same constraints created using MASConstraintMaker
```obj-c
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(superview.mas_top).with.offset(padding.top); //with is an optional semantic filler
make.left.equalTo(superview.mas_left).with.offset(padding.left);
make.bottom.equalTo(superview.mas_bottom).with.offset(-padding.bottom);
make.right.equalTo(superview.mas_right).with.offset(-padding.right);
}];
```
Or even shorter
```obj-c
[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(superview).with.insets(padding);
}];
```
Also note in the first example we had to add the constraints to the superview `[superview addConstraints:...`.
Masonry however will automagically add constraints to the appropriate view.
Masonry will also call `view1.translatesAutoresizingMaskIntoConstraints = NO;` for you.
## Not all things are created equal
> `.equalTo` equivalent to **NSLayoutRelationEqual**
> `.lessThanOrEqualTo` equivalent to **NSLayoutRelationLessThanOrEqual**
> `.greaterThanOrEqualTo` equivalent to **NSLayoutRelationGreaterThanOrEqual**
These three equality constraints accept one argument which can be any of the following:
#### 1. MASViewAttribute
```obj-c
make.centerX.lessThanOrEqualTo(view2.mas_left);
```
MASViewAttribute | NSLayoutAttribute
------------------------- | --------------------------
view.mas_left | NSLayoutAttributeLeft
view.mas_right | NSLayoutAttributeRight
view.mas_top | NSLayoutAttributeTop
view.mas_bottom | NSLayoutAttributeBottom
view.mas_leading | NSLayoutAttributeLeading
view.mas_trailing | NSLayoutAttributeTrailing
view.mas_width | NSLayoutAttributeWidth
view.mas_height | NSLayoutAttributeHeight
view.mas_centerX | NSLayoutAttributeCenterX
view.mas_centerY | NSLayoutAttributeCenterY
view.mas_baseline | NSLayoutAttributeBaseline
#### 2. UIView/NSView
if you want view.left to be greater than or equal to label.left :
```obj-c
//these two constraints are exactly the same
make.left.greaterThanOrEqualTo(label);
make.left.greaterThanOrEqualTo(label.mas_left);
```
#### 3. NSNumber
Auto Layout allows width and height to be set to constant values.
if you want to set view to have a minimum and maximum width you could pass a number to the equality blocks:
```obj-c
//width >= 200 && width <= 400
make.width.greaterThanOrEqualTo(@200);
make.width.lessThanOrEqualTo(@400)
```
However Auto Layout does not allow alignment attributes such as left, right, centerY etc to be set to constant values.
So if you pass a NSNumber for these attributes Masonry will turn these into constraints relative to the view’s superview ie:
```obj-c
//creates view.left = view.superview.left + 10
make.left.lessThanOrEqualTo(@10)
```
Instead of using NSNumber, you can use primitives and structs to build your constraints, like so:
```obj-c
make.top.mas_equalTo(42);
make.height.mas_equalTo(20);
make.size.mas_equalTo(CGSizeMake(50, 100));
make.edges.mas_equalTo(UIEdgeInsetsMake(10, 0, 10, 0));
make.left.mas_equalTo(view).mas_offset(UIEdgeInsetsMake(10, 0, 10, 0));
```
By default, macros which support [autoboxing](https://en.wikipedia.org/wiki/Autoboxing#Autoboxing) are prefixed with `mas_`. Unprefixed versions are available by defining `MAS_SHORTHAND_GLOBALS` before importing Masonry.
#### 4. NSArray
An array of a mixture of any of the previous types
```obj-c
make.height.equalTo(@[view1.mas_height, view2.mas_height]);
make.height.equalTo(@[view1, view2]);
make.left.equalTo(@[view1, @100, view3.right]);
````
## Learn to prioritize
> `.priority` allows you to specify an exact priority
> `.priorityHigh` equivalent to **UILayoutPriorityDefaultHigh**
> `.priorityMedium` is half way between high and low
> `.priorityLow` equivalent to **UILayoutPriorityDefaultLow**
Priorities are can be tacked on to the end of a constraint chain like so:
```obj-c
make.left.greaterThanOr
没有合适的资源?快使用搜索试试~ 我知道了~
iOS 仿支付宝银行卡层叠效果
共122个文件
h:19个
m:16个
plist:4个
需积分: 38 32 下载量 128 浏览量
2018-06-22
09:46:47
上传
评论
收藏 254KB ZIP 举报
温馨提示
仿支付宝之前的我的银行卡列表层叠效果,简单易用,易修改
资源推荐
资源详情
资源评论
收起资源包目录
iOS 仿支付宝银行卡层叠效果 (122个子文件)
0038ddcb7ae4a4056696dcd9aa538b0af7697a 631B
060ed28827ed6aca9565d946e6b5595c8978df 231B
0760158e7d00b59909d82ecf97737b1702a0d3 58B
07b235c8e0cbec30cd7f7c19c87b74b1ef604a 4KB
0fd960827d384dbc1f979e4ee10ad76ce30231 811B
17a5b0c248c5f1407f3fa7c431c387a67f21ae 280B
1bf13e23041c954954ab1ab18e7eda82944809 2KB
1d8cda6861fc0752ff1366b18d7bd50cbfb669 1KB
1e8ae7bebd7dacd24045facae28bb4da38cc8b 1KB
206e33174ac4543637d0d12ae059e42f2c6a41 69B
219496f3217bce05637c9abafec39ef52d9fd1 221B
30b592eb9ff37dd9777d3c38a95e2609b9cf06 174B
31025d7ff3336a0f7db2a6e33a518d55317c3b 504B
3181660e05adee62ff6e457b07e0bf9fe6b608 131B
3b68d62d60b48a9a5890b5243345cf19abe8df 1KB
3f6fd5810b9c852cf98563d82d5ed1e84ff893 804B
3fa76b979b55c760ec0f654a164ff1d963f515 149B
40a264428fe2a578b305b79befc00d05f8aed6 2KB
40a6cd0c4af2f0d93b697fbfb066793681b045 352B
43c00c260d8ce378dec6b57fd0e766233ce646 665B
460569efce5424fa975938dd32e92fea6c211b 866B
4736977e3ae5c1124a00552f81c7d5815df4de 383B
49c6da9343a27624c8a42757a9d37bb5e77d27 68B
4c35b50efa7749431cf709215eb36667acd71c 175B
4c6f166e0d1f85a3fe72e14c81a1f0767f46cf 298B
4ec1041274f1306ce0d1be509facc16ee2afe3 2KB
5139fac520a13bec9f705f132ca512f5fc1117 337B
59a484760c1347be2a195eda232f3980e8bd42 6KB
6279ab02da37622415094f560e892b1fa72dd9 313B
628ee8e62deaa7facdfdcce119762744962600 235B
63d4ad5a4016fad28abfd5270c6c54cc179929 93B
63ed63b432881d1af75c6f50cac0017d845b02 1KB
66c6a562dccef0ae8e3ca11436976009b6121e 139B
66fc8aa16f2c4145d5701bf74fc4c070573dc4 168B
69cf81bbb4eaec9c4f037cba53e49c5d1512da 1KB
6d393f0a891b0c5a1e37dcb9a8706c2c4e5ff0 58B
6e2464e3f4a6f905bf4a08bf292b1853923a3c 126B
72b4c431366302b5228d4f439341dacd40388b 1KB
7410092d84a7c0c25bef3ba0da3174d42bc23c 52B
78f7ad7c097d04c59f87539277ab6d2cf51791 573B
79b4fd850a63c8f3a97a08d0fc538a3af887c0 225B
7fe21beb39dd96b34d0bab0656e8835d1cbef1 2KB
83f026d925d8c40c38cb14d5c58a1d3ff2b078 161B
8a0e135b251f3bfe3760fb3f5429f8b269289c 286B
9041cbf10228d35f6b1a88aace981059b47e56 322B
9f89b85ec9191157517324a807c9f8d9a8b32e 95B
a10c8ee3d2fa65eba3ca167a56dc104d851726 2KB
a2e302773e8a22ea96733dd12a8e127f6b8d4b 57B
a5623865800ad7d0e8edc6b4e55104f391159f 130B
a801e25622cbc8d7e30951dd73cb2fd628898d 3KB
ad166ac67b91f8de3be076dcd2d073b4549cf5 256B
bbe40dabdcaa69fdb05a9cb3677892b1064766 907B
bd579d463e4d6f9e4d0a9dcf66ed9f65b8e155 354B
be23d52078f341e202bb939b2d2ae3a61b01f2 779B
be3b681122de83e380d47b840b7d0486f71f86 540B
bfd938fdd1b2efab917ac90fa63ef714fc7fb1 2KB
c78a1255c016bde922c849eef8555881c207b6 768B
ca9c939a7aa5d7f242118c95d9e21c1b4d04c1 453B
COMMIT_EDITMSG 15B
config 137B
d26eeb25df15939ed7eb9919ffe65e898514cf 91B
description 73B
.DS_Store 6KB
eb70002a77dfc0bcd34ae4aeb772085d640180 555B
exclude 40B
fb48d0a9298fd438b0e007acee16b873891ee3 479B
fd1fa796fbb779d7cae5ab17a8299b76dec928 341B
MASConstraint.h 7KB
MASUtilities.h 6KB
MASConstraintMaker.h 5KB
View+MASAdditions.h 4KB
View+MASShorthandAdditions.h 4KB
NSArray+MASAdditions.h 3KB
MASConstraint+Private.h 2KB
MASViewConstraint.h 1KB
MASViewAttribute.h 1KB
NSArray+MASShorthandAdditions.h 1016B
ViewController+MASAdditions.h 891B
Masonry.h 802B
MASLayoutConstraint.h 505B
MASCompositeConstraint.h 494B
COMMON.h 373B
NSLayoutConstraint+MASDebugAdditions.h 326B
AppDelegate.h 265B
ZXLMainViewController.h 215B
ZXLBankCardCell.h 202B
HEAD 157B
HEAD 23B
index 5KB
Contents.json 1KB
LICENSE 1KB
MASViewConstraint.m 13KB
MASConstraintMaker.m 10KB
MASConstraint.m 8KB
ZXLBankCardCell.m 7KB
NSArray+MASAdditions.m 6KB
NSLayoutConstraint+MASDebugAdditions.m 6KB
View+MASAdditions.m 5KB
MASCompositeConstraint.m 5KB
AppDelegate.m 2KB
共 122 条
- 1
- 2
资源评论
weixin_42516690
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功