#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)
**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;
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.greaterThanOrEqualTo(label.mas_left).with.priorityLow();
make.top.equalTo(label.mas_top).wi
没有合适的资源?快使用搜索试试~ 我知道了~
一套IM完整的UI实现方案_Objective-C_Makefile_下载.zip
共2367个文件
png:622个
h:328个
dia:241个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 66 浏览量
2023-04-24
13:47:30
上传
评论
收藏 104.66MB ZIP 举报
温馨提示
一套IM完整的UI实现方案_Objective-C_Makefile_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
一套IM完整的UI实现方案_Objective-C_Makefile_下载.zip (2367个子文件)
libAFNetworking.a 1.23MB
libAFNetworking.a 1.09MB
libSDWebImage.a 771KB
libSDWebImage.a 707KB
libMasonry.a 411KB
libMasonry.a 366KB
libTTTAttributedLabel.a 290KB
libTTTAttributedLabel.a 256KB
libXXNibBridge.a 57KB
libXXNibBridge.a 47KB
libPods.a 5KB
libPods.a 4KB
assetcatalog_dependencies 1KB
assetcatalog_dependencies 1KB
Assets.car 42KB
Assets.car 42KB
ChatKitDemo 2.15MB
ChatKitDemo 2.15MB
CodeResources 69KB
ChatCollectionViewController.d 4KB
ChatCollectionViewController.d 4KB
ChatViewController.d 3KB
ChatCollectionCell.d 3KB
ChatViewController.d 3KB
ChatCollectionCell.d 3KB
BubblePressHandleHelper.d 3KB
ChatDemoDataSourceHelper.d 3KB
ChatCell.d 3KB
BubblePressHandleHelper.d 3KB
ChatDemoDataSourceHelper.d 3KB
ChatCell.d 3KB
BubbleVideoView.d 2KB
BubbleTextView.d 2KB
BubblePhotoView.d 2KB
BubbleVideoView.d 2KB
MessageSendHelper.d 2KB
BubbleLocationView.d 2KB
LocationMessageModel.d 2KB
BubbleTextView.d 2KB
BubbleVoiceView.d 2KB
VideoMessageModel.d 2KB
VoiceMessageModel.d 2KB
PhotoMessageModel.d 2KB
BubblePhotoView.d 2KB
TextMessageModel.d 2KB
IMServiceHelper.d 2KB
MessageSendHelper.d 2KB
MediaAttachmentHelper.d 2KB
BubbleLocationView.d 2KB
LocationMessageModel.d 2KB
BubbleVoiceView.d 2KB
VideoMessageModel.d 2KB
PhotoMessageModel.d 2KB
VoiceMessageModel.d 2KB
TextMessageModel.d 2KB
MessageModel.d 2KB
IMServiceHelper.d 2KB
MediaAttachmentHelper.d 2KB
DownloadFileHelper.d 2KB
MessageServiceModel.d 2KB
MessageModel.d 2KB
DownloadFileHelper.d 2KB
UpLoadFileHelper.d 2KB
CacheHelper.d 2KB
BottomMoreView.d 2KB
MoreViewBtn.d 2KB
MessageServiceModel.d 2KB
UpLoadFileHelper.d 2KB
CacheHelper.d 2KB
BottomMoreView.d 2KB
MoreViewBtn.d 2KB
BottomEmotionFaceView.d 2KB
EmotionFaceToolBar.d 2KB
KeyBoardToolBarView.d 2KB
EmotionBoardView.d 2KB
KeyBoardView.d 2KB
BottomEmotionFaceView.d 2KB
EmotionFaceToolBar.d 2KB
KeyBoardToolBarView.d 2KB
EmotionBoardView.d 2KB
KeyBoardView.d 2KB
UIButton+AFNetworking.d 1KB
UIButton+AFNetworking.d 1KB
UIImageView+AFNetworking.d 1KB
UIImageView+AFNetworking.d 1KB
AFImageDownloader.d 1KB
AFImageDownloader.d 994B
MASConstraintMaker.d 966B
MASViewConstraint.d 965B
SDWebImageDownloaderOperation.d 963B
UIWebView+AFNetworking.d 937B
SDWebImageDownloaderOperation.d 923B
MASConstraintMaker.d 922B
MASViewConstraint.d 921B
UIWebView+AFNetworking.d 901B
UIImageView+HighlightedWebCache.d 881B
UIActivityIndicatorView+AFNetworking.d 867B
AFNetworkActivityIndicatorManager.d 861B
UIImageView+WebCache.d 859B
PhotoGalleryScrollView.d 853B
共 2367 条
- 1
- 2
- 3
- 4
- 5
- 6
- 24
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python爬取淘宝热卖商品并可视化分析
- 5152单片机proteus仿真和源码将按键次数写入AT24C02再读出并用1602LCD显示
- SE-SSD复现过程(Det3D的安装教程)
- 基于Python的在线学习与推荐系统设计与实现(论文+源码)-kaic
- 串口通过 YMODEM 协议进行文件传输
- 蓝桥杯2024年第十五届省赛真题-前缀总分
- com.qihoo.appstore_300101305-1.apk
- tensorflow-gpu-2.7.1-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp37-cp37m-manylinux2010-x86-64.whl
- tensorflow-2.7.1-cp39-cp39-manylinux2010-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功