#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
没有合适的资源?快使用搜索试试~ 我知道了~
滚动视图嵌套解决方案 .zip
共156个文件
h:58个
m:50个
plist:8个
需积分: 3 0 下载量 159 浏览量
2024-01-15
11:37:12
上传
评论
收藏 858KB ZIP 举报
温馨提示
方案是为解决特定问题或达成特定目标而制定的一系列计划或步骤。它的作用是提供一种系统性的方法,以有效地应对挑战、优化流程或实现目标。以下是方案的主要作用: 问题解决: 方案的核心目标是解决问题。通过系统性的规划和执行,方案能够分析问题的根本原因,提供可行的解决方案,并引导实施过程,确保问题得到合理解决。 目标达成: 方案通常与明确的目标相关联,它提供了一种达成这些目标的计划。无论是企业战略、项目管理还是个人发展,方案的制定都有助于明确目标并提供达成目标的路径。 资源优化: 方案在设计时考虑了可用资源,以最大化其效用。通过明智的资源分配,方案可以在有限的资源条件下实现最大的效益,提高效率并减少浪费。 风险管理: 方案通常会对潜在的风险进行评估,并制定相应的风险管理策略。这有助于减轻潜在问题的影响,提高方案的可行性和可持续性。 决策支持: 方案提供了决策者所需的信息和数据,以便做出明智的决策。这种数据驱动的方法有助于减少不确定性,提高决策的准确性。 团队协作: 复杂的问题通常需要多个人的协同努力。方案提供了一个共同的框架,帮助团队成员理解各自的职责和任务,促进协作并确保整个团队朝着共同的目标努力。 监控与评估: 方案通常包括监控和评估的机制,以确保实施的有效性。通过定期的评估,可以及时调整方案,以适应变化的环境或新的挑战。 总体而言,方案的作用在于提供一种有序、有计划的方法,以解决问题、实现目标,并在实施过程中最大化资源利用和风险管理。
资源推荐
资源详情
资源评论
收起资源包目录
滚动视图嵌套解决方案 .zip (156个子文件)
.DS_Store 6KB
.DS_Store 6KB
Untitled.gif 731KB
.gitignore 1KB
UIButton+WebCache.h 13KB
SDWebImageManager.h 11KB
UIImageView+WebCache.h 10KB
SDImageCache.h 9KB
MASConstraint.h 7KB
SDWebImageDownloader.h 7KB
MASUtilities.h 6KB
MASConstraintMaker.h 5KB
UIImageView+HighlightedWebCache.h 5KB
View+MASAdditions.h 4KB
SDWebImagePrefetcher.h 4KB
View+MASShorthandAdditions.h 4KB
SDWebImageDownloaderOperation.h 3KB
NSArray+MASAdditions.h 3KB
YBLevelListController.h 3KB
YBLevelListConfigModel.h 3KB
SDWebImageCompat.h 2KB
YBNestContainerView.h 2KB
MASConstraint+Private.h 2KB
YBLevelListView.h 2KB
MASViewConstraint.h 1KB
MASViewAttribute.h 1KB
NSArray+MASShorthandAdditions.h 1016B
UIView+WebCacheOperation.h 970B
YBNestContentProtocol.h 917B
ViewController+MASAdditions.h 891B
UIView+YB.h 814B
SDWebImage-umbrella.h 802B
Masonry.h 802B
Masonry-umbrella.h 801B
MultstageScrollViewHeader.h 768B
YbWebView.h 640B
NSData+ImageContentType.h 565B
MASLayoutConstraint.h 505B
MASCompositeConstraint.h 494B
SDWebImageDecoder.h 453B
PicAndTextTableView.h 395B
EvaluateTableView.h 392B
UIImage+GIF.h 382B
GoodsDetailsVC.h 375B
YBNestContainerLayout.h 353B
Pods-YBMultistageScrollView-umbrella.h 346B
SDWebImageOperation.h 329B
UIScrollView+YBNestViews.h 329B
YBLevelListSubView.h 328B
NSLayoutConstraint+MASDebugAdditions.h 326B
NestSubController.h 322B
YBNestViews.h 308B
NestSubSpaceView.h 307B
NestSubView.h 300B
AppDelegate.h 299B
AppDelegate.h 284B
YBNestCollectionView.h 277B
NestMainController.h 276B
ViewController.h 268B
YBNestTableView.h 265B
UIImage+MultiFormat.h 263B
ViewController.h 237B
Contents.json 2KB
Contents.json 753B
Contents.json 62B
LICENSE 1KB
LICENSE 1KB
LICENSE 1KB
Manifest.lock 376B
Podfile.lock 376B
YBLevelListView.m 24KB
SDImageCache.m 23KB
SDWebImageDownloaderOperation.m 18KB
SDWebImageManager.m 15KB
MASViewConstraint.m 13KB
UIButton+WebCache.m 12KB
UIImageView+WebCache.m 12KB
SDWebImageDownloader.m 11KB
MASConstraintMaker.m 10KB
YBLevelListController.m 8KB
YBNestContainerView.m 8KB
MASConstraint.m 8KB
GoodsDetailsVC.m 7KB
NSArray+MASAdditions.m 6KB
NSLayoutConstraint+MASDebugAdditions.m 6KB
View+MASAdditions.m 5KB
UIImageView+HighlightedWebCache.m 5KB
UIImage+GIF.m 5KB
SDWebImagePrefetcher.m 5KB
YbWebView.m 5KB
MASCompositeConstraint.m 5KB
NestMainController.m 4KB
SDWebImageDecoder.m 4KB
PicAndTextTableView.m 3KB
UIImage+MultiFormat.m 3KB
NestSubController.m 3KB
NestSubView.m 3KB
EvaluateTableView.m 3KB
AppDelegate.m 2KB
UIView+YB.m 2KB
共 156 条
- 1
- 2
资源评论
JJJ69
- 粉丝: 5966
- 资源: 5593
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功