TableViewCell的分割线显示不完全处理方法

1、加方法,隐藏分割线

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    //设置tableView不能滚动

    [self.tableView setScrollEnabled:NO];

    //在此处调用一下就可以啦 :此处假设tableView的name叫:tableView

    [self setExtraCellLineHidden:self.tableView];

}

-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];

}

2cell显示内容时候,用图片替换

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 

 staticNSString *cellID =@"Cell";

    _cell = [tableViewdequeueReusableCellWithIdentifier:cellID];

    

    if (_cell ==nil) {

        _cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellID];

 

     UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width,1.0f)];

    separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];

    separatorLine.tag = 4;

    [cell.contentView addSubview:separatorLine];

 

UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];

separatorLine.hidden = NO;

 

    }

   UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];

   separatorLine.hidden = NO;


3、自定义的cell,在上面画自己画一条线和屏幕宽度一样长

 

UITableView中将分割线样式改为None 

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

 

自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法 

- (void)drawRect:(CGRect)rect { 

CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect); //上分割线

CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);

CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割线 CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor); CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1));

 }

 

4、重写父类的方法

-(void)viewDidLayoutSubviews {
    
    if ([self.mytableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.mytableview setSeparatorInset:UIEdgeInsetsZero];

    }
    if ([self.mytableview respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.mytableview setLayoutMargins:UIEdgeInsetsZero];
    }

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值