iOS UITableViewCell分割线设置

2019-05-28  本文已影响0人  QianQianPeng

除掉UITableView底部多余行及分割线:

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

隐藏所有的分割线:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

分割线颜色:

self.tableview.separatorColor = [UIColor redColor];

分割线边距:

//定制表格单元分割线
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellIdentifier];

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 25, 0, 0)];
    }
    return cell;
}
//定制表格单元分割线
  -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 25, 0, 0)];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 25, 0, 0)];
    }
}
 -(void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    self.tableView.tableFooterView = [UIView new];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,15,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
    [self.tableView reloadData];
}
上一篇 下一篇

猜你喜欢

热点阅读