IOS UI Basics Nine Gongge algorithm

Source: Internet
Author: User

Case Analysis:

Analysis:

Code Case implementation:

//

Viewcontroller.m

01-Nine Lattice algorithm

//

Created by Flylee on 14-9-12.

Copyright (c) 2014 Flylee. CN. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

/*

Data container

*/

@property (Nonatomic,strong) Nsarray *apps;

@end

@implementation Viewcontroller

Lazy Loading

-(Nsarray *) apps

{

if (_apps = = nil) {

1. Get the full path to the plist file

NSString *path = [[NSBundle mainbundle] pathforresource:@ "app.plist" oftype:nil];

2. Loading an array

_apps = [Nsarray Arraywithcontentsoffile:path];

}

return _apps;

}

-(void) viewdidload

{

[Super Viewdidload];

Additional setup after loading the view, typically from a nib.

1. Number of columns in each row

int totalcol = 3;

2. Constants for the dimensions and y values of each lattice

CGFloat APPW = 85;

CGFloat APPH = 90;

CGFloat starty = 30; Set the initial position of Y, battery bar 20 so the initial position setting 30

CGFloat marginy = 15; Set the initial gap space for Y

3. Clearance = (width of the Controller view-3 * grid)/4;

CGFloat Marginx = (Self.view.frame.size.width-totalcol * appw)/(Totalcol + 1);

int count = Self.apps.count;

4. Based on the number of application management, create a grid

for (int i = 0; i < count; i++) {

4.1 CREATE View

UIView *appview = [[UIView alloc] init];

Appview.backgroundcolor = [Uicolor Redcolor];

4.2 Calculating line numbers and column numbers

i = 0, 1, 2/3 = 0 The initial is 0 lines start 0, 1, 2, 3 ....

i = 3, 4, 5/3 = 1

int row = I/totalcol;

i = 0, 3, 6 3 = 0 The initial is 0 columns start 0, 1, 2, 3 ....

i = 1, 4, 7%3 = 1

int col = i% Totalcol;

4.3 Calculating x and Y

CGFloat AppX = Marginx + (APPW + marginx) * COL;

CGFloat appy = Starty + (APPH + marginy) * ROW;

Appview.frame = CGRectMake (Appx,appy, APPW,APPH);

4.4 Adding a grid to the view of the controller

[Self.view Addsubview:appview];

}

}

-(void) didreceivememorywarning

{

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

IOS UI Basics Nine Gongge algorithm

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.