天天看點

iOS8 設定TableView Separatorinset 分割線從邊框頂端開始

在iOS7上 [ self.tableView setSeparatorInset : UIEdgeInsetsMake ( 0 , 0 , 0 , 0 )]; (UIRectEdgeNone)

經過測試加入下面方法 在iOS7、8上都可以正常工作

-(void)viewDidLayoutSubviews

{

    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {

        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {

        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];

    }

}

-(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];

    }

}

繼續閱讀