# 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.greaterThanO
没有合适的资源?快使用搜索试试~ 我知道了~
iOS商城毕业设计.zip
共943个文件
h:358个
png:223个
m:189个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 26 浏览量
2024-02-25
14:24:24
上传
评论 1
收藏 8.36MB ZIP 举报
温馨提示
iOS商城毕业设计.zip 一个iOS端的商城项目,实现了简单的购物流程以及商家的管理功能。数据库为Sqlite,本地数据库。 这是一个非常好的练习项目,通过此项目可以学习到很多关于iOS开发的基础控件的使用以及逻辑问题处理。 同时,这也是我第一个完整的iOS项目,并且用这个项目是我的毕设,用时一个半月。 普通用户账号:15152863606 密码:111111 管理员账号:13814437090 密码:111111 普通用户的账号是可以注册的,但是管理员的账号是不可以注册的。
资源推荐
资源详情
资源评论
收起资源包目录
iOS商城毕业设计.zip (943个子文件)
FMDatabase.h 52KB
AFURLSessionManager.h 29KB
AFURLRequestSerialization.h 22KB
AFHTTPSessionManager.h 20KB
SDWebImageManager.h 14KB
AFURLResponseSerialization.h 12KB
FMResultSet.h 12KB
NSButton+WebCache.h 12KB
UIButton+WebCache.h 11KB
NSObject+MJKeyValue.h 10KB
SDWebImageDownloader.h 10KB
SDImageCache.h 10KB
UIButton+AFNetworking.h 10KB
AFImageDownloader.h 9KB
UIImageView+WebCache.h 9KB
AFNetworkReachabilityManager.h 8KB
MASConstraint.h 8KB
FMDatabaseQueue.h 8KB
SDCycleScrollView.h 7KB
FMDatabasePool.h 7KB
UIView+WebCache.h 7KB
FMDatabaseAdditions.h 6KB
AFAutoPurgingImageCache.h 6KB
MASUtilities.h 6KB
UIImageView+AFNetworking.h 6KB
AFSecurityPolicy.h 6KB
MASConstraintMaker.h 6KB
AFNetworkActivityIndicatorManager.h 5KB
View+MASAdditions.h 5KB
SDWebImageDownloaderOperation.h 5KB
View+MASShorthandAdditions.h 5KB
SDWebImageTransition.h 4KB
UIWebView+AFNetworking.h 4KB
UIImageView+HighlightedWebCache.h 4KB
SDWebImageCoder.h 4KB
SDWebImagePrefetcher.h 4KB
NSObject+MJProperty.h 3KB
NSObject+MJClass.h 3KB
NSArray+MASAdditions.h 3KB
SDWebImageCompat.h 3KB
UIProgressView+AFNetworking.h 2KB
UIView+Toast.h 2KB
SDWebImageCoderHelper.h 2KB
SDWebImageCodersManager.h 2KB
MJExtensionConst.h 2KB
DBProductDetail.h 2KB
UIRefreshControl+AFNetworking.h 2KB
UIActivityIndicatorView+AFNetworking.h 2KB
TAPageControl.h 2KB
DBProduct.h 2KB
MASConstraint+Private.h 2KB
UIKit+AFNetworking.h 2KB
SDCollectionViewCell.h 2KB
SZKImagePickerVC.h 2KB
AFNetworking.h 2KB
SDImageCacheConfig.h 2KB
MJProperty.h 2KB
DBOrderDetail.h 1KB
LMJDropdownMenu.h 1KB
UIView+SDExtension.h 1KB
DBShoppingCartDetail.h 1KB
UIView+WebCacheOperation.h 1KB
AddProductView.h 1KB
UIImage+AFNetworking.h 1KB
NSString+MJExtension.h 1KB
MASViewConstraint.h 1KB
SDWebImageImageIOCoder.h 1KB
WaitPayView.h 1KB
MASViewAttribute.h 1KB
SDWebImageFrame.h 1KB
DBUser.h 1KB
MJPropertyType.h 1KB
DBComment.h 1KB
UIImage+MultiFormat.h 1KB
DetailsModel.h 1KB
NSObject+MJCoding.h 1KB
NSArray+MASShorthandAdditions.h 1016B
SDWebImageGIFCoder.h 1015B
DBOrderList.h 984B
NSData+ImageContentType.h 969B
SingleTableView.h 915B
ViewController+MASAdditions.h 891B
Masonry.h 802B
SDAnimatedImageRep.h 793B
DBForum.h 764B
ManagerView.h 746B
OrderAdressView.h 743B
DBShoppingCart.h 697B
MJPropertyKey.h 680B
DBAddress.h 676B
UIImage+GIF.h 663B
MyMessageNormalUser.h 656B
ShoppingCartListCell.h 647B
ProductListSearchModel.h 612B
ClassView.h 611B
SingleListModel.h 600B
DBPayMent.h 590B
ShoppingCartListModel.h 579B
DetailsTitleLabelView.h 573B
ForumDetialView.h 570B
共 943 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- supeerzdj2024-04-03这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
武昌库里写JAVA
- 粉丝: 6682
- 资源: 3166
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 打造最强的Java安全研究与安全开发面试题库,帮助师傅们找到满意的工作.zip
- (源码)基于Spark的实时用户行为分析系统.zip
- (源码)基于Spring Boot和Vue的个人博客后台管理系统.zip
- 将流行的 ruby faker gem 引入 Java.zip
- (源码)基于C#和ArcGIS Engine的房屋管理系统.zip
- (源码)基于C语言的Haribote操作系统项目.zip
- (源码)基于Spring Boot框架的秒杀系统.zip
- (源码)基于Qt框架的待办事项管理系统.zip
- 将 Java 8 的 lambda 表达式反向移植到 Java 7、6 和 5.zip
- (源码)基于JavaWeb的学生管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功