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