欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UITableViewCell的分割线左侧对齐

程序员文章站 2022-07-15 19:06:13
...

一般设置cell时使用    

    cell.separatorInset = UIEdgeInsetsMake(top, left, bottom, right);

 但此方法不能使分割线对齐屏幕最左边

 

在tableView代理中设置可以是分割线左对齐

- (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];
    }
    
    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
}

 

相关标签: ios Objective-C