iOS Development-masonry

Source: Internet
Author: User

Masonry is a third-party framework that encapsulates Apple AutoLayout. Simplifies code addition constraints, and so on.

Https://github.com/SnapKit/Masonry
After downloading the unzip, drag the masonry folder into the project.

Here's a small example:
First import the header file:

#import "Masonry/Masonry.h"
    [[UIView alloc]init];    [buleView setBackgroundColor:[UIColor blueColor]];    [self.view addSubview:buleView];    [buleView mas_makeConstraints:^(MASConstraintMaker *make) {        //大小        make.size.mas_equalTo(CGSizeMake(5050));        //位置:居中        make.center.mas_equalTo(self.view);    }];

Run, there is a 50*50 blue small square in the center of the screen.

Masonry some of the constraints inside the method:

    [buleView mas_makeConstraints:^(MASConstraintMaker *make) {        //添加新约束    }];    [buleView mas_remakeConstraints:^(MASConstraintMaker *make) {        //会把以前的约束删除掉,添加新的约束    }];    [buleView mas_updateConstraints:^(MASConstraintMaker *make) {        //更新以前的约束    }];

An example of referencing a masonry document:
The effect is a view that has a 10 margin between the top and bottom of the parent control. The official list of two types of writing, the second direct sentence to achieve results.
The first type:

Uiedgeinsets padding = Uiedgeinsetsmake (Ten,Ten,Ten,Ten);[View1 mas_makeconstraints:^ (Masconstraintmaker *make) {Make. Top. Equalto(Superview. Mas_top). with. Offset(padding. Top);//with is an optional semantic fillerMake. 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);}];

The second type:

[view1 mas_makeConstraints:^(MASConstraintMaker *make) {    make.edges.equalTo(superview).with.insets(padding);}];

Here we will encounter a lot of mas_ prefixes and do not have this prefix of things, the difference between them is that with Mas_ prefix is the parameters are encapsulated, for example:
Mas_equalto (100)
Equalto (@100)
No mas_ prefixes need to be transferred to the type, or vice versa.
If you want to equate these two effects, then masonry provides two macros for us to use, but it is important to note that when defining this macro, before importing the masonry header file, for example:

constantiftofordefaultconstantiftouse‘mas"Masonry/Masonry.h"

That's all you can do.

iOS Development-masonry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.