2014-01-25 46 views
0

此代码在UITableView的顶部和底部创建边距。我如何修改它以做到这一点,但在每个人之间UITableViewCell如何在UITableViewCells之间应用此页眉/页脚边距?

// set header height 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 10; 
} 

// set header colour 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] init]; 
    headerView.backgroundColor = [UIColor lightGrayColor]; 
    return headerView; 
} 

// set footer height 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    return 10; 
} 

// set footer colour 
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] init]; 
    headerView.backgroundColor = [UIColor lightGrayColor]; 
    return headerView; 
} 

如果成功的话,我还希望能够如有可能添加类似于左,右页边距。

+0

每个单元格的部分可能是您正在寻找的部分。对于左/右边距:自定义单元格可以做到这一点。 – Larme

+0

我将如何修改该代码?我在这个方向上的尝试迄今都不成功...... – Sebastian

+0

你有一个返回行数的方法,另一个返回分节数。反转这些数字,并修改cellForRowAtIndexPath。 – Larme

回答

1

enter image description here

使用一个额外的背景UIView与顶部,左侧。底部和右边距[图片中的红色背景视图]。在这个视图中添加所有其他的子视图。