iOS application nine Gongge algorithm

Source: Internet
Author: User

1, the box horizontal interval is: ("The total width of the interface"-"the width of the control of each line of the interface" * "The number of columns per line to be realistic (here is 3)")/("Number of columns + 1")

2, Box vertical interval can be customized to write dead

3, each box horizontal position is: (box width + interval width) multiplied by (column number)

4. The position of each frame is: (box height + interval width) multiplied by (line number) + top interval [here is 30]

5, each box in the first few rows of the algorithm is: The line number is "box ordinal to the number of columns", the column number is "box ordinal column modulo"

/** arranges the view generated by the array according to the required "Number of columns", "box width", "box height" */
-(void) Rankwithtotalcolumns: (int) totalcolumns ANDWITHAPPW: (int) APPW ANDWITHAPPH: (int) apph{
Total number of columns
int _totalcolumns = Totalcolumns;

View Size
CGFloat _APPW = APPW;
CGFloat _apph = APPH;

Transverse clearance (width of Controller view-Number of columns * application width)/(Number of columns + 1)
CGFloat margin = (Self.view.frame.size.width-(_totalcolumns *))/(_totalcolumns + 1);

for (int index = 0; index < self.appsArray.count; index++) {
Create a small box//
UIView *appview = [[UIView alloc] init];
Appview.backgroundcolor = [Uicolor Redcolor];
End of Creation//

Calculate the position of the box ... Line number column number starting from 0
Line number
int row = Index/totalcolumns; Row number box ordinal to column number of the vendor
Column number
int col = index% Totalcolumns; Column number is the ordinal of the box to the number of columns to take the remainder

CGFloat AppX = margin + col * (appw + margin); The width of each box on the left is (average interval + box own width)
CGFloat Appy = + Row * (apph + margin); The height of each box above is the average interval + the height of the box itself

Appview.frame = CGRectMake (AppX, Appy, _APPW, _APPH);

[Self.view Addsubview:appview];
}
}

iOS application nine Gongge algorithm

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.