iOS Development Adaptive Screen IX Gongge (third-party library masonry)

Source: Internet
Author: User

Transfer from http://blog.sina.com.cn/s/blog_13fd67a560102wil5.html

Used to record the last created Uilabel

UILabel *lastlabel = nil;

for (int i = 0; i < 9; i++) {

UILabel *label = [UILabel new];

Label.textalignment = Nstextalignmentcenter;

Label.text = [NSString stringwithformat:@ "~%d~", I];

[Self.view Addsubview:label];

[Label mas_makeconstraints:^ (Masconstraintmaker *make) {

Set height

Make.height.offset (40.0f);

Calculates the formula at the top of the distance 60 = the height of the previous distance above the top + Uilabel

Float Coltop = (+ I/3 * 60.0f);

Make.top.offset (Coltop);

When the left column is the distance from the parent view to the left 20

if (i%3 = = 0) {

Make.left.offset (20.0f);

}else{

When the middle column was on the right side of the previous Uilabel, add 20 distances and set the equal height

Make.width.equalTo (Lastlabel.mas_width);

Make.left.equalTo (lastlabel.mas_right). Offset (20.0f);

}

//When it is the rightmost column, the distance from the right parent view is 20 because it is left so 20 control bottom is negative!

if (i%3 = = 2) {

Make.right.offset ( -20.0f);

}

}];

LastLabel = label;

}

iOS Development Adaptive Screen IX Gongge (third-party library 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.