//总列数 int totalColumns=3; CGFloat appW = 95; CGFloat appH = 85; //间隙 CGFloat maginX = (self.view.frame.size.width - totalColumns*appW)/(totalColumns+1); CGFloat maginY = 20; for (int i=0; i<self.plistData.count; i++) { UIView * appView = [[UIView alloc] init]; appView.backgroundColor=[UIColor redColor]; CGFloat col = i%totalColumns; CGFloat row = i/totalColumns; CGFloat appX =col*(appW+maginX)+maginX; CGFloat appY= row*(appH+maginY)+maginY; appView.frame=CGRectMake(appX, appY,appW, appH); [self.view addSubview:appView]; }
时间: 2024-10-12 17:15:20