viernes, 30 de septiembre de 2016

iOS: Remove left gap from row separator

Objective C

#pragma mark - UITableViewDelegate method

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove seperator inset
    if ([cell respondsToSelector : @selector (setSeparatorInset :)]) {
        [cell setSeparatorInset : UIEdgeInsetsZero ];
    }
    
    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector : @selector (setPreservesSuperviewLayoutMargins :)]) {
        [cell setPreservesSuperviewLayoutMargins : NO ];
    }
    
    // Set Your explictly cell's layout margins
    if ([cell respondsToSelector : @selector (setLayoutMargins :)]) {
        [cell setLayoutMargins : UIEdgeInsetsZero ];
    }

}

Swift

// In viewDidLoad
tableView?.cellLayoutMarginsFollowReadableWidth = false

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if cell.responds(to: #selector(setter: UITableViewCell.separatorInset)) {
            cell.separatorInset = UIEdgeInsets.zero
        }
        if cell.responds(to: #selector(setter: UIView.preservesSuperviewLayoutMargins)) {
            cell.preservesSuperviewLayoutMargins = false
        }
        if cell.responds(to: #selector(setter: UIView.layoutMargins)) {
            cell.layoutMargins = UIEdgeInsets.zero
        }
    }

No hay comentarios:

Publicar un comentario