+0
日增长
18,113
stars
3,141
forks
694
watchers
147
prs
464
issues
1
releases
README
Masonry !Pod Version
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 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 simpTop issues
#461v1.1.0 crash with UIView margins43 comments · 2017-09-20#477v 1.1.0 safeAreaLayoutGuide Crsah20 comments · 2017-10-13#418Demo crash when click Bacony Labels, and Margins11 comments · 2017-01-24#367Duplicate definition9 comments · 2016-07-27#344Add Hugging and CompressionResistance Please9 comments · 2016-05-18#578查找两个view最近公共祖先那段逻辑算法复杂度是O(n²),可以优化8 comments · 2020-06-11#551view设置了高度为0.8,但是打印出来是17 comments · 2019-02-13#479width怎么往某一方向展开7 comments · 2017-10-24
Latest release
Xcode 9 / iOS 11 v1.1.0 2017-09-20Fixes build warnings for Xcode 9 / iOS 11 Adds support for safeLayoutGuide on iOS 11