关于tableViewCell的一些事情
2015-11-03 09:44
211 查看
前面几天公司要求将目前app中的分割线统一颜色样式,有一个重点要求就是分割线的宽度必须是一个 像素,这个简单的任务自然就交了我这个newbie了。
刚接到这个任务,看到二十四个界面需要修改,我以为这是一个繁琐的事情,开始的目标也很明确,找出各个界面与分割线相关的代码修改,修改的过程中我发现了cell 的分割线是两种不同的一种是系统自定义的一种是通过代码来设定的,代码如下:首先设定cell 的separator的样式为空然后
UIImageView* lineViewFoot = [[UIImageView alloc]initWithFrame:CGRectMake(0, 44, _tongtongTable.frame.size.width, 0.5)];
lineViewFoot.backgroundColor = LINE_COLOR_220 ;
[cell.contentView addSubview:lineViewFoot];
到了这里应该怎么办呢?选择代码?太麻烦 而且需要重新设定系统的,选择系统的又不知道是不是符合要求,于是就有了下面的测定系统的分割线的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text = @"test";
if (indexPath.row == 2) {
cell.contentView.backgroundColor = [UIColor blackColor];
}else if (indexPath.row == 3){
cell.contentView.backgroundColor = [UIColor redColor];
}else{
cell.contentView.backgroundColor = [UIColor blueColor];
}
NSLog(@"这个是cell的contentview的高度%f",cell.contentView.frame.size.height);
NSLog(@"这个是cell的高度 %f",cell.frame.size.height);
tableView.separatorColor = [UIColor redColor];
return cell;
}
运行的结果如下图:
而输出的结果就在这里:
输出
2015-11-02 15:22:47.218 test[7872:208077] 这个是cell 的contentview的高度47.500000
2015-11-02 15:22:47.218 test[7872:208077] 这个是cell 的高度 48.000000
从这些可以看出系统的cell 的分割线就是一个像素。后面的处理就简单了很多
其他的收获就需要自己总结了
hope it helps!
刚接到这个任务,看到二十四个界面需要修改,我以为这是一个繁琐的事情,开始的目标也很明确,找出各个界面与分割线相关的代码修改,修改的过程中我发现了cell 的分割线是两种不同的一种是系统自定义的一种是通过代码来设定的,代码如下:首先设定cell 的separator的样式为空然后
UIImageView* lineViewFoot = [[UIImageView alloc]initWithFrame:CGRectMake(0, 44, _tongtongTable.frame.size.width, 0.5)];
lineViewFoot.backgroundColor = LINE_COLOR_220 ;
[cell.contentView addSubview:lineViewFoot];
到了这里应该怎么办呢?选择代码?太麻烦 而且需要重新设定系统的,选择系统的又不知道是不是符合要求,于是就有了下面的测定系统的分割线的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text = @"test";
if (indexPath.row == 2) {
cell.contentView.backgroundColor = [UIColor blackColor];
}else if (indexPath.row == 3){
cell.contentView.backgroundColor = [UIColor redColor];
}else{
cell.contentView.backgroundColor = [UIColor blueColor];
}
NSLog(@"这个是cell的contentview的高度%f",cell.contentView.frame.size.height);
NSLog(@"这个是cell的高度 %f",cell.frame.size.height);
tableView.separatorColor = [UIColor redColor];
return cell;
}
运行的结果如下图:
而输出的结果就在这里:
输出
2015-11-02 15:22:47.218 test[7872:208077] 这个是cell 的contentview的高度47.500000
2015-11-02 15:22:47.218 test[7872:208077] 这个是cell 的高度 48.000000
从这些可以看出系统的cell 的分割线就是一个像素。后面的处理就简单了很多
其他的收获就需要自己总结了
hope it helps!
相关文章推荐
- 去除TableView的边框线. (分割线 ,下划线就这个意思)
- UITableViewCell的展开与收缩功能实现分析
- iOS—TableView的分割线从边框顶端开始
- iOS tableVIewCell的使用总结
- iOS7,iOS8,TableViewCell分割线不顶格,在ViewController里面加上下面的俩个方法即可
- ios tableViewCell滑动实现多按钮
- iOS UITableViewCell重用问题
- IOS 学习笔记(9)tableView基础
- IOS学习笔记(11)TableView中移动cell和section
- iOS自定义cell导致数据加载混乱
- 空行line.separator
- Sliding TableViewCell
- Input TableViewCell
- Quadrant TableViewCell
- Popover TableViewCell
- Social Share TableViewCell
- Auto Resizing Editable TableViewCell
- tableviewCell 从array数组中加载数据
- [iOS]在tableview中用动画效果改变cell的高度
- tabletableView的cell点击 跳转页面 出现延迟的状况