How to set the full width of separator in UITableView

前端 未结 16 844
再見小時候
再見小時候 2020-11-30 19:50

I have a UITableView where the separators don\'t have the full width. It ends like 10 pixels before the left side. I was playing around with this code in the

16条回答
  •  旧巷少年郎
    2020-11-30 20:40

    I got the answer from this post: iOS 8 UITableView separator inset 0 not working

    Just add this code on your UITableViewController

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

提交回复
热议问题