@interfaceViewcontroller () @property (nonatomic,strong) Nsarray*apps;//get. plist data@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //total columns of nine Gongge inttotalcolumns=5; //size of 1.1 squaresCGFloat appw= -; CGFloat APPH= -; //2. Calculate clearance = (width of controller view -5* application width)/application width +1CGFloat margin= (SELF.VIEW.FRAME.SIZE.WIDTH-TOTALCOLUMNS*APPW)/(totalcolumns+1); //3. The number of applications to create the corresponding lattice for(intindex=0; index<self.apps.count; index++) { //3.1 Creating 1 latticesUIView *appview=[[UIView alloc]init]; //Set Background colorAppview.backgroundcolor=[Uicolor Redcolor]; //3.2 Calculating line numbers and column numbers intRow =index/Totalcolumns; intCol =index%Totalcolumns; CGFloat AppX=margin+ col* (APPW +margin); CGFloat Appy= -+ row* (APPH +margin); Appview.frame=CGRectMake (AppX, Appy, APPW, APPH); //3.3 Adding a grid to the view of the controller[Self.view Addsubview:appview]; } }
IOS Nine Gongge algorithm