IOS显示九宫格列表

    //总列数
    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];
    }

 

posted @ 2015-10-17 16:09  老树昏鸦  阅读(469)  评论(0编辑  收藏  举报