iOS7에서는 separatorInset을 UIEdgeInsetsZero로 주면 테이블뷰의 separator 라인의 마진이 없어졌었다.

하지만 iOS8에서는 separatorInset이 아닌 layoutMargin으로 바뀌었다.

테이블뷰에서 직접설정하면 되지만 커스텀 셀을 사용하는 경우 cell에 layoutMargin처리를 해야 제대로 동작한다.

 

하지만, 커스텀 셀이 많은 경우 테이블뷰의 willDisplayCell 딜리게이트를 이용해 다음과 같이 처리하면 보다 적은양의 코드로 처리가 가능하다.

 

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

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

        [tableView setSeparatorInset:UIEdgeInsetsZero];

    }

    

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

        [tableView setLayoutMargins:UIEdgeInsetsZero];

    }

    

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

        [cell setLayoutMargins:UIEdgeInsetsZero];

    }

}

 

 

Categories:

Tags:

2 Responses

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다