iOS-创建表格

2017-08-15  本文已影响71人  DivilMayCry

基于九宫格做了一些小改进, 形成了简单的边框表格

简略效果图

-(void)tableTetsWithCol:(NSInteger)colCount Total:(NSInteger)total{
    
    
    UIView *BGV = [UIView tc_InitWithBlock:^(UIView *imgView) {
        imgView.tc_FrameValue(10,100,[UIScreen mainScreen].bounds.size.width - 20,200).tc_BGColorEnum(tcColor_White).tc_SuperView(self.view);
    }];
    
    
    for (int i = 0; i < total; i++) {
        
        NSUInteger row = i/colCount;
        NSUInteger col = i%colCount;
        NSInteger itemW = (BGV.frame.size.width - 30)/colCount;
        
        CGRect rect = CGRectMake(10 + col*itemW, 10+row*30, itemW, 30);
        
        if (col > 0) {
            rect.origin.x -= col;
        }
        
        if (row > 0) {
            rect.origin.y -= row;
        }
        
        UILabel *label = [UILabel tc_InitWithBlock:^(UILabel *label) {
            label.tc_FrameRect(rect).tc_BGColor([UIColor whiteColor]).tc_SuperView(BGV);
            
        }];
        
        label.text = @"lalal";
        
        label.textAlignment = NSTextAlignmentCenter;
        
        label.layer.borderColor = [UIColor lightGrayColor].CGColor;
        
        label.layer.borderWidth = 1;
        
    }
    
}

上一篇下一篇

猜你喜欢

热点阅读