Use of the masonry framework-uniform equidistant distribution of multiple views

Source: Internet
Author: User

__weak typeof (self) weakself = self; Weak the self, or cause a circular reference to fail to release the controller

UIView * Tempview = [[UIView alloc]init];
Nsinteger count = 10;//Sets the number of rows of view
Nsinteger margin = 10;//Set distance apart
Nsinteger height = 50;//Sets the altitude of the view
for (int i = 0; i < count; i + +) {
UIView * view = [[UIView alloc]init];
View.backgroundcolor = [Uicolor Browncolor];
[Self.view Addsubview:view];
if (i = = 0) {
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (Weakself.view). offset (margin);
Make.centerY.equalTo (Weakself.view);
Make.height.mas_equalTo (height);
}];
}
else if (i = = count–1) {
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.right.equalTo (Weakself.view). Offset (-margin);
Make.left.equalTo (tempview.mas_right). offset (margin);
Make.centerY.equalTo (Tempview);
Make.height.equalTo (Tempview);
Make.width.equalTo (Tempview);
}];
}
else{
[View mas_makeconstraints:^ (Masconstraintmaker *make) {
Make.left.equalTo (tempview.mas_right). offset (margin);
Make.centerY.equalTo (Tempview);
Make.height.equalTo (Tempview);
Make.width.equalTo (Tempview);
}];
}
Tempview = view;
[View layoutifneeded];
}

Use of the masonry framework-uniform equidistant distribution of multiple views

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.