首页 > 代码库 > IOS代码库

IOS代码库

 1 /* 九宫格计算 */ 2 int totalCol = 5;//指定总列数 3  4 CGFloat viewW = 50;//subview宽度 5 CGFloat viewH = 50;//subview高度 6  7 CGFloat marginX = (self.view.bounds.size.width-viewW*totalCol)/(totalCol+1);//计算横向空白间隙 8 CGFloat marginY = marginX;//计算纵向空白间隙(和横向一致) 9 10 for (int i = 0; i<self.appList.count; i++) {//遍历plist中的view信息 一次在view中生成appview11     12     int col = i%totalCol;//计算appview所在的列13     int row = i/totalCol;//计算appview所在的行14     15     CGFloat x = col*viewW+(col+1)*marginX;//计算appview的横坐标16     CGFloat y = row*viewH+(row+1)*marginY;//计算appview的纵坐标17     18     UIView *appView = [[UIView alloc] initWithFrame:CGRectMake(x, y, viewW, viewH)];19     appView.backgroundColor = [UIColor redColor];//设置appview20     21     [self.view addSubview:appView];//添加到view中22 }23 24 /* 懒加载 */25 -(NSArray *)appList26 {27 if (!appList) {28     NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"plist"];29     appList = [NSArray arrayWithContentsOfFile:path];//加载plist方法30     NSLog(@"%@",appList);31 }32 return appList;33 }