IOS-Interface: Build the originator-jiugongge algorithm, ios-jiugong

Source: Internet
Author: User

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.

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.