您的位置:首页 > 其它

关于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!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tableviewcell separator