ios 多列表格
2017-03-20 21:13
148 查看
可能是一直忙着赶项目,所以已这个为借口很久都没有写博客了,今天突然看到一篇文章谈到写博客的重要性,才刚看了开头。我就已经意识到,应该不定时的写点儿什么东西出来。虽然平时对开发有做笔记。但是都没有整理成博客发表出来,整理的东西都是针对自己的项目当中的。不过应该还是有点儿帮助吧。
在项目当中有个需要用到多列表格的东西。我以为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];
}];
}];
}
截图:
在项目当中有个需要用到多列表格的东西。我以为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];
}];
}];
}
截图:
相关文章推荐
- IOS 表格边框上添加阴影
- 给iOS SDK中的表格控件(UITableView)添加背景图
- IOS超强表格控件GMGridView
- ispreedSheet ios编辑类似表格界面在ipad上
- iOS中如何使用表格
- ios开发之webView.scalesPageToFit = YES后 加载页面遇见表格显示很小的解决方法
- iOS学习之分段Table View的使用(Grouped样式表格)
- ios表格cell的编辑和删除
- 【iOS开发】---- 表格滚动时隐藏及显示导航条和标签栏
- iOS学习之分段Table View的使用(Grouped样式表格)
- iOS学习之分段Table View的使用(Grouped样式表格)
- iOS表格视图 GMGridView
- iOS开源:表格视图GMGridView
- 【IOS】表态表格的使用
- iOS开源:UITableview圆形排列的表格视图UITableViewTricks
- ios UITableView表格实现搜索栏搜索
- IOS - 自定义表格(UITableView)
- IOS表格
- ios表格的操作
- IOS超强表格控件GMGridView