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