IOS-Interface: Build the originator-jiugongge algorithm, ios-jiugong
Steps for building a gugongge:
Define what view is used for each piece
Define the parent-child relationship between each view
First try to add the grids one by one, and finally consider using the for Loop
Load app data and create the corresponding number of grids Based on the Data Length
Add a child control inside the grid
Assemble data for child controls inside the grid
:
Code:
-(Void) viewDidLoad {[super viewDidLoad]; // build the interface-jiugongge !! # Define kAppViewH 80 // each small view height 80 # define kAppViewW 80 // each small view width 80 # define kColCount 3 // a certain number of views per line, all three # define kStart 20 // adapt to the screen, starting point 20 CGFloat Margat = (self. view. bounds. size. width-kColCount * kAppViewW)/(kColCount + 1); // The x value of each column must be CGFloat marginY = 10; // The Y value of each row must be determined by the row number for (int I = 0; I <12; I ++) {// The row number int row = I/kColCount; // The column number int col = I % kColCount; // x-CGFloat x = Margat + col * (kAppViewW + marginX) is determined by the column number ); // y-CGFloat y = kStart + marginY + row * (kAppViewH + marginY) determined by the row number; // CGFloat UIView * appView = [[UIView alloc] initWithFrame: CGRectMake (x, y, kAppViewW, kAppViewH)]; appView. backgroundColor = [UIColor redColor]; [self. view addSubview: appView] ;}}
Running result:
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.