自己封装的一个GridView控件
2013-04-22 19:03
246 查看
效果如图:
使用方法:
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_colorArray = [NSArray
arrayWithObjects:[UIColor
redColor],[UIColor
yellowColor],[UIColor
blueColor],[UIColor
greenColor], nil];
MyGridView* gridView = [[MyGridView
alloc]initWithFrame:CGRectMake(0,
0, 320,
460)];
gridView.dataSource =
self;
gridView.delegate =
self;
[gridView
setRowSpanning:10.0f];
[gridView
setColumnNumber:ColumnNumber];
[gridView
setColumnSpanning:10.0f];
[self.view
addSubview:gridView];
[gridView
reloadData];
}
-(CGFloat)gridView:(MyGridView *)gridView heightOfRow:(NSInteger)row{
return 80;
}
-(NSInteger)numberOfGridView:(MyGridView *)gridView{
return 60;
}
-(void)gridView:(MyGridView *)gridView didSelectWithIndex:(NSInteger)index
{
NSLog(@"点击的索引是:%d",index);
}
-(UITableViewCell *)gridView:(MyGridView *)gridView cellForIndex:(NSInteger)index{
NSString * cellID =
@"mycell";
UITableViewCell* cell = [gridView
dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellID];
}
UIColor * color = [_colorArray
objectAtIndex:(index%ColumnNumber+(int)(index/ColumnNumber))%ColumnNumber];
[cell
setBackgroundColor:color];
return cell;
}
需要实现Delegate和DataSource
下载地址:
http://download.csdn.net/detail/hahahakonghee/5285573
使用方法:
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_colorArray = [NSArray
arrayWithObjects:[UIColor
redColor],[UIColor
yellowColor],[UIColor
blueColor],[UIColor
greenColor], nil];
MyGridView* gridView = [[MyGridView
alloc]initWithFrame:CGRectMake(0,
0, 320,
460)];
gridView.dataSource =
self;
gridView.delegate =
self;
[gridView
setRowSpanning:10.0f];
[gridView
setColumnNumber:ColumnNumber];
[gridView
setColumnSpanning:10.0f];
[self.view
addSubview:gridView];
[gridView
reloadData];
}
-(CGFloat)gridView:(MyGridView *)gridView heightOfRow:(NSInteger)row{
return 80;
}
-(NSInteger)numberOfGridView:(MyGridView *)gridView{
return 60;
}
-(void)gridView:(MyGridView *)gridView didSelectWithIndex:(NSInteger)index
{
NSLog(@"点击的索引是:%d",index);
}
-(UITableViewCell *)gridView:(MyGridView *)gridView cellForIndex:(NSInteger)index{
NSString * cellID =
@"mycell";
UITableViewCell* cell = [gridView
dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellID];
}
UIColor * color = [_colorArray
objectAtIndex:(index%ColumnNumber+(int)(index/ColumnNumber))%ColumnNumber];
[cell
setBackgroundColor:color];
return cell;
}
需要实现Delegate和DataSource
下载地址:
http://download.csdn.net/detail/hahahakonghee/5285573
相关文章推荐
- 自己封装实现的仿GridView的列表控件
- 封装一个用户控件的pager.ascx文件供自己使用
- 自己项目用的一个控件,自己封装的
- cocos2d-x自己封装的一个 等待的控件 TTWaitting
- 自己动手用Javascript写一个无刷新分页控件
- ASP.NET AJAX客户端编程之旅(六)——来做一个自己的客户端控件
- UISearchBar 去边框 改背景 (蛮恶心得控件 不如UITextFile 自己封装个)
- 从NSURLSession到AFNetworking再到自己封装一个网络框架
- 给某个标签,添加事件(onclick、change等事件),有两种,1在html标签中直接加上事件 2在页面加载完成后,在ready函数中给标签添加事件,特别是对于自己封装的控件如box,一般都是用2
- MVC为Html对象建立一个扩展方法,使用自己的控件就像使用TextBox一样方便
- 自己封装的一个LoadRes组件
- 尝试封装一个自己的模块
- 自己封装的一个java图片验证码
- 写了一个SpringMVC 怎么封装到Map里!以后要多多利用这种方法,自己脑子笨就记下来了。
- 分享一个自己抽象出来的Manager管理类,封装增删改,查的方法
- 自己使用js/jquery写的一个定制对话框控件
- VB.Net自己写的一个控件:ComboBox下拉列表中显示多列数据(可以绑定数据表)
- 一个树控件类的实现---打造自己的树控件
- 一个封装android开发常用控件的库
- 自己封装的一个原生JS拖动方法(推荐)