美文网首页iOS开发
iOS cell分割线设置

iOS cell分割线设置

作者: 天明依旧 | 来源:发表于2016-04-14 14:11 被阅读1212次

UITableView 实现类似中间那条线

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
        if (indexPath.row < dataSource.count - 1) {
            //四个参数:上左下右
            cell.separatorInset=UIEdgeInsetsMake(0, 16, 0, 0);
        }
    }
    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
//隐藏多余分割线
-(void)setExtraCellLineHidden: (UITableView *)tableView

{
    
    UIView *view = [UIView new];
    
    view.backgroundColor = [UIColor clearColor];

    [tableView setTableFooterView:view];
    
}

相关文章

网友评论

    本文标题:iOS cell分割线设置

    本文链接:https://www.haomeiwen.com/subject/squglttx.html