定制单元格
2014-04-10 15:30
232 查看
1.UItTableViewController
标示图控制器
两种单元格类型
UITableViewCellStyleDefault 不支持子标题
UITableViewCellStyleSubtitle 支持子标题
都支持图片与主题
另外两种单元格类型
UITableViewCellStyleValue1
UITableViewCellStyleValue2
都不支持 图片
--------------------------定制单元格------------------------
1.通过UITableViewCell的contentView属性添加子视图
static NSString *identifier = @"firstId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]autorelease];
/*
不会改变的内容放在括号的里面去写
*/
//创建子视图
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(200, 0, 100, 44)];
label.tag = 123;
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
/*
会改变的内容放在括号的外面面去写
*/
NSDictionary *dic = [_newsList objectAtIndex:indexPath.row];
//获取时间的文本
UILabel *timeLabel = (UILabel *)[cell.contentView viewWithTag:123];
timeLabel.text = [NSString stringWithFormat:@"%@小时之前",dic[@"time"]];
cell.textLabel.text = dic[@"title"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@条评论",[dic objectForKey:@"commentCount"]];
2.使用xib自定义视图,布局十分方便,开发较为迅速
if (cell == nil) {
//同xib文件创建的
/*
用xib文件创建的时候
一定要把UITableViewCell 的identifier属性手动的设置上
*/
cell = [[[NSBundle mainBundle]loadNibNamed:@"SecondCell" owner:self options:nil]lastObject];
}
获取工程主路径 加载xib 选择视图
3.子类化UITableViewCell,更加面向对象
- (void)_initViews
{
//创建标题文本
_t
4000
itleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = [UIFont boldSystemFontOfSize:14];
_titleLabel.textColor = [UIColor orangeColor];
[self.contentView addSubview:_titleLabel];
//其他视图
}
- (void)layoutSubviews
{
//必须写的**********
[super layoutSubviews];
//进行布局
_titleLabel.frame = CGRectMake(10, 5, 200, 20);
_titleLabel.text = [self.dic objectForKey:@"title"];
//其他
}
标示图控制器
两种单元格类型
UITableViewCellStyleDefault 不支持子标题
UITableViewCellStyleSubtitle 支持子标题
都支持图片与主题
另外两种单元格类型
UITableViewCellStyleValue1
UITableViewCellStyleValue2
都不支持 图片
--------------------------定制单元格------------------------
1.通过UITableViewCell的contentView属性添加子视图
static NSString *identifier = @"firstId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]autorelease];
/*
不会改变的内容放在括号的里面去写
*/
//创建子视图
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(200, 0, 100, 44)];
label.tag = 123;
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
/*
会改变的内容放在括号的外面面去写
*/
NSDictionary *dic = [_newsList objectAtIndex:indexPath.row];
//获取时间的文本
UILabel *timeLabel = (UILabel *)[cell.contentView viewWithTag:123];
timeLabel.text = [NSString stringWithFormat:@"%@小时之前",dic[@"time"]];
cell.textLabel.text = dic[@"title"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@条评论",[dic objectForKey:@"commentCount"]];
2.使用xib自定义视图,布局十分方便,开发较为迅速
if (cell == nil) {
//同xib文件创建的
/*
用xib文件创建的时候
一定要把UITableViewCell 的identifier属性手动的设置上
*/
cell = [[[NSBundle mainBundle]loadNibNamed:@"SecondCell" owner:self options:nil]lastObject];
}
获取工程主路径 加载xib 选择视图
3.子类化UITableViewCell,更加面向对象
- (void)_initViews
{
//创建标题文本
_t
4000
itleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = [UIFont boldSystemFontOfSize:14];
_titleLabel.textColor = [UIColor orangeColor];
[self.contentView addSubview:_titleLabel];
//其他视图
}
- (void)layoutSubviews
{
//必须写的**********
[super layoutSubviews];
//进行布局
_titleLabel.frame = CGRectMake(10, 5, 200, 20);
_titleLabel.text = [self.dic objectForKey:@"title"];
//其他
}
相关文章推荐
- 单元格的三种定制方式
- 定制 WinForm DataGrid单元格格式
- UI连载十-----------表视图单元格定制
- 在TTTableViewController定制单元格
- 定制单元格的用户界面。
- UITableViewController+定制单元格
- 译文:构建DataGridView的定制NumericUpDown单元格(Cell)和表格列(Column)
- tableView的单元格的定制的方法
- 定制 UITableViewCell 表视图单元格
- Swift开发iOS应用(2)定制单元格
- 定制UITableView的单元格
- 定制单元格
- 【ios学习记录】-如何定制UITableView的圆角单元格
- 定制单元格的几种方式
- UI初级第八课  定制单元格——iOS学习连载23
- 建DataGridView的定制NumericUpDown单元格(Cell)和表格列(Column
- IOS UI初级-表视图单元格定制
- 备忘-给UITabelView内的单元格分别定制高度
- Winform编程中定制窗体标题栏
- 更改命令库函数复制脚本-定制小型linux