美文网首页
iOS-创建表格

iOS-创建表格

作者: DivilMayCry | 来源:发表于2017-08-15 13:48 被阅读71次

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

    简略效果图
    
    -(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;
            
        }
        
    }
    
    

    相关文章

      网友评论

          本文标题:iOS-创建表格

          本文链接:https://www.haomeiwen.com/subject/lkomrxtx.html