#import "SFViewController.h"
@interface SFViewController ()
@property (nonatomic,strong)NSArray * array;
@end
@implementation SFViewController
-(NSArray *)array
{
if(_array ==nil){
NSString * path = [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil];
_array = [NSArray arrayWithContentsOfFile:path];
}
return _array;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//添加应用信息
//间隙=(控制器的宽度的宽度-3*应用的宽度)
//应用的尺寸
CGFloat viewW = 85;
CGFloat viewH = 90;
int columns = 3;//总列数
CGFloat marginX =(self.view.frame.size.width-columns*viewW)/(columns+1);
CGFloat marginY =20;
for(int index=0;index<self.array.count;index++){
UIView * view = [[UIView alloc]init];//创建一个view
//间隙的位置
int row = index/columns;//行号
int col = index%columns;//列号
CGFloat viewX = marginX+col*(viewW+marginX);//间隙
CGFloat viewY = 30+row*(viewH+marginY);
//view的位置
view.frame = CGRectMake(viewX, viewY, viewW, viewH);
view.backgroundColor = [UIColor redColor];
//添加到控件的view
[self.view addSubview:view];
}
}