Masonry: A bound third-party class library

Source: Internet
Author: User
Masonry is quite simple and easy to use. Worthy of being a third party with over 2000 likes.

Let's take a look at the specific usage.

UIView *gr = UIView.new;    gr.backgroundColor = [UIColor greenColor];    UIView *re = UIView.new;    re.backgroundColor = [UIColor redColor];    UIView *ye = UIView.new;    ye.backgroundColor = [UIColor yellowColor];    [self.view addSubview:gr];    [self.view addSubview:re];    [self.view addSubview:ye];        UIView *superView = self.view;        [gr mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.equalTo(superView.mas_left).offset(50);        make.top.equalTo(superView.mas_top).offset(64+50);        make.width.equalTo(@50);        make.height.equalTo(@50);    }];    [re mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.greaterThanOrEqualTo(gr.mas_right).offset(20);        make.top.equalTo(superView.mas_top).offset(64+70);        make.width.equalTo(gr.mas_width).multipliedBy(2);        make.height.equalTo(gr.mas_height).multipliedBy(2);    }];    [ye mas_makeConstraints:^(MASConstraintMaker *make) {        make.edges.equalTo(re).insets(UIEdgeInsetsMake(20, 10, 15, 20));    }];

Let's take a look at it with a picture.

First, let's look at the figure and look at the code. It's easy to understand, define three color views, and set constraints respectively. The block contains constraints, which are simple and tough, except for one-to-one settings, you can also use edge to set the view constraints at a time. Just look at the yellow view contained in the red view.

 

What can he do? Look at this.

It basically contains all the enumerations, and then look at the composite type:

 

 

 

We can see that this is basically usable. However, we can continue to explore some other features:

Yarn

Masconstraint

This class contains many block methods, which are used to obtain restricted objects. For specific functions, see the API or try it by yourself. Haha.

The above

Multiple Constraints multipliedby, you often need to set the size of the view based on the screen size, so this can help you deal with it.

 

By the way, how should I deploy uiscrollview?

In ConstraintsUIScrollViewIf you want to scroll horizontally, you mustUIScrollViewThe left and right sides. Similarly, for vertical scrollingUIScrollViewThe upper and lower sides.


In addition, there is a method mas_updateconstraints which is used to update constraints. The constraint is updated. The problem arises and the view must be changed. You can use the animation or call the method layoutifneeded directly:

[Uiview animatewithduration: 0.3 delay: 0.0f options: uiviewanimationoptioncurveeaseout animations: ^ {[self. view layoutifneeded];} completion: NULL .. Thanks to the powerful author

Masonry: A bound third-party class library

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.