Steps to build nine Gongge:
Identify what the view is for each piece
Identify the parent-child relationship between each view
Try adding the grid one by one, and finally consider using the For loop
Load app data to create a corresponding number of squares based on the data length
Adding child controls inside a lattice
Assemble data to child controls inside the lattice
:
Code:
- (void) viewdidload{[SuperViewdidload];//Build interface-NINE!! #define KAPPVIEWH 80//Each small view high#define KAPPVIEWW 80//Each small view width#define KCOLCOUNT 3/Per line View number must be three#define Kstart 20//Adaptation screen, starting with CGFloatMarginx = ( Self. View. Bounds. Size. Width-Kcolcount * kappvieww)/(Kcolcount +1);//The x value of each column must CGFloatMarginy =Ten;//The Y value of each row must be determined by the line number for(intI=0; i< A; i++) {//Line number introw = I/kcolcount;//Column number intcol = I%kcolcount;//x-determined by column number CGFloatx = Marginx + col * (Kappvieww + Marginx);//y-determined by line number CGFloaty = kstart + marginy + row * (KAPPVIEWH + marginy);//cgfloat UIView*appview = [[UIViewAlloc]initwithframe:cgrectmake (x, Y, Kappvieww, KAPPVIEWH)]; Appview. BackgroundColor= [UicolorRedcolor]; [ Self. ViewAddsubview:appview]; }}
Operation Result:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The Gongge algorithm of ios-Interface building of the originator _ Nine