2014-01-25 26 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與頂部,左側。底部和右邊距[圖片中的紅色背景視圖]。在這個視圖中添加所有其他的子視圖。