tabview----分割线的位置

现在很多项目中都需要自己去绘制cell的分割线来满足需要,本人刚开始也是觉得有系统就好了,但是为了配合项目的需要我们不得不去解决这样的问题。

其实只需要如下这样子就可以实现分割线的控制。

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    //这是绘制其中一条线的位置,其他同理
    if (indexPath.row ==2) {
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
            [cell setSeparatorInset:UIEdgeInsetsMake(0,0, 0, 800)];
        }
     
      //这个判断是关键,只有设置这个才能绘制位置(参考stackflow的做法)
        if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
            [cell setPreservesSuperviewLayoutMargins:NO];
        }
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
            }
    }
    else{
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
            [cell setSeparatorInset:UIEdgeInsetsMake(0, 47, 0, 19)];
        }
    }
}
如果要直接使用TableView的sectionTitle,但又想设置它的字体,颜色什么的,可以使用如下方法。 
- (void)tableView:(UITableView )tableView willDisplayHeaderView:(UIView )view forSection:(NSInteger)section 
{ 
// Background color 
view.tintColor = [UIColor blueColor];

// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor redColor]];

// Another way to set the background color
// Note: does not preserve gradient effect of original header
// header.contentView.backgroundColor = [UIColor blackColor];
}

 

 

 

posted @ 2016-08-03 10:04  qinxiaoguang  阅读(308)  评论(0编辑  收藏  举报