Masonry recording--ios adaptation

Source: Internet
Author: User

Masonry is an iOS adaptation of the third-party library, the more useful one, I use not much, a simple understanding of some common methods, their own learning, record down mutual encouragement.

Masonry:
Https://github.com/SnapKit/Masonry

Example one: View Center processing

In any case, the view is in the center state

__weak typeof (self) weakself = self;

UIView * view = [UIView new];

View.backgroundcolor = [Uicolor Redcolor];

[Self.view Addsubview:view];

    // Adding a constraint using mas_makeconstraints

[View mas_makeconstraints:^ (Masconstraintmaker *make) {

// add size constraint ( make is the control you want to add the constraint to view,size is set the view size )

Make.size.mas_equalTo (Cgsizemake (100, 100));

// Add center constraint (centered with self , center set to center)

Make.center.equalTo (Weakself.view);

}];

Example two: A constraint between two view

Add a new view

UIView * Blackview = [UIView new];

Blackview.backgroundcolor = [Uicolor blackcolor];

[Self.view Addsubview:blackview];

Add a constraint to a black view

[Blackview mas_makeconstraints:^ (Masconstraintmaker *make) {

// Add size constraint (set black view size to 100,size to width)

Make.size.mas_equalTo (Cgsizemake (100, 100));

// add left, top margin constraints (both left and top constraints are 20,left.and.top to set both the left margin and margin )

Make.left.and.top.mas_equalTo (20);

}];

Masonry recording--ios adaptation

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.