ios 多列表格

可能是一直忙着赶项目,所以已这个为借口很久都没有写博客了,今天突然看到一篇文章谈到写博客的重要性,才刚看了开头。我就已经意识到,应该不定时的写点儿什么东西出来。虽然平时对开发有做笔记。但是都没有整理成博客发表出来,整理的东西都是针对自己的项目当中的。不过应该还是有点儿帮助吧。

在项目当中有个需要用到多列表格的东西。我以为tableView可以完成类似的功能。查了半天都没有搞定。所以最后决定自己用线条来画吧。这也是这个自定义多列表格的核心,还是挺简单的。

.h文件:

#import <UIKit/UIKit.h>

@interface UserLevelEXPTabelView : UIView

/*
 使用说明:
 //设置数据
 NSArray *array = @[@[@"俱乐部等级",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"],@[@"游戏房间数量",@"2",@"2",@"2",@"2",@"2",@"2",@"2",@"2"],@[@"管理员数量",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"]];
 //设置行高,列,行数(不包括头这一行),
 [_levelTabelView setTableWithRowHeight:70 coumn:3 row:8 dataArray:array];
 */
@property (nonatomic,strong) NSArray *arrayTitle;//标题头名称

- (void) setTableWithRowHeight:(CGFloat) rowHeight coumn:(NSInteger) column row:(NSInteger) row dataArray:(NSArray *)array;
@end

.m文件:

#import "UserLevelEXPTabelView.h"
#import "BQScreenAdaptation.h" //等比例适配工具
@implementation UserLevelEXPTabelView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
#pragma mark -- Function
- (void) setupUI{
    
}
- (void) setTableWithRowHeight:(CGFloat) rowHeight coumn:(NSInteger) column row:(NSInteger) row dataArray:(NSArray *)array{
    //画横线
    for(NSInteger i=0;i<row+2;i++){
        UIView *line = [[UIView alloc]initWithFrame:BQAdaptationFrame(0, i*rowHeight, IPHONE_WIDTH-40, 1.0)];
        line.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line];
    }
    //画竖线
    CGFloat margin = (IPHONE_WIDTH-40.0) / column;
    CGFloat height = rowHeight * (row+1);
    for(NSInteger i=0;i<column+1;i++){
        UIView *line = [[UIView alloc]initWithFrame:BQAdaptationFrame(i*margin, 0, 1.0, height)];
        line.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line];
    }
    //添加label
    [array enumerateObjectsUsingBlock:^(NSArray *  _Nonnull obj, NSUInteger idx1, BOOL * _Nonnull stop) {
        [obj enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj2, NSUInteger idx2, BOOL * _Nonnull stop) {
            UILabel *label = [[UILabel alloc]initWithFrame:BQAdaptationFrame(idx1*margin, idx2*rowHeight, margin, rowHeight)];
            label.text = obj2;
            label.font = [UIFont systemFontOfSize:28*BQAdaptationWidth()];
            label.textAlignment = NSTextAlignmentCenter;
            [self addSubview:label];
        }];
    }];
}
截图:






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值