<pre name="code" class="objc">//
// ViewController.m
// 0811-jiugongge
//
// Created by panba on 15-8-11.
// Copyright (c) 2015年 panba. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) NSArray *applist;
@end
@implementation ViewController
-(NSArray *)applist
{
if (!_applist) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"app" ofType:@"plist"];
_applist = [NSArray arrayWithContentsOfFile:path];
}
return _applist;
}
-(void)viewDidLoad
{
[super viewDidLoad];
//UIView *view = [[UIView alloc] init];
int totolcol = 3;
CGFloat viewWidth = 80;
CGFloat viewHeight = 90;
CGFloat marginx = (self.view.bounds.size.width - totolcol*viewWidth)/(totolcol+1);
CGFloat marginy = 20;
CGFloat starty = 30;
int row ;
int col;
CGFloat x;
CGFloat y;
for (int i=0; i<self.applist.count; i++)
{
row = i/totolcol;
col = i%totolcol;
x = marginx + col*(viewWidth+marginx);
y = starty + row*(viewHeight+marginy);
UIView *appview = [[UIView alloc]init];
appview.frame = CGRectMake(x, y, viewWidth, viewHeight);
appview.backgroundColor = [UIColor redColor];
[self.view addSubview:appview];
}
//创建imageview
uiimageview *imageview = [[uiimageview alloc] init ];
imageview.frame = cgrectmake (0,0,viewWidth,50);
imageview.backgroundcolor = [uicolor redcolor];
[appview addsubview:imageview];
}
@end