2014-02-11 213 views

回答

6

你可以通過設置你的背景,你想要的任何背景(假設灰色在這種情況下)做到這一點,在細胞中,添加一個白色的UIView與左,右和下邊緣是這樣的:

enter image description here

然後轉到您的表視圖,設置分隔符爲無

enter image description here

和最後一步,設置你的表視圖的背景,相同的灰色背景爲您的電池。

enter image description here

然後,你不必做任何事情,特別是在你的代碼除了簡單地基於自定義筆尖文件最初的表格單元格(我假設你無論如何要做到這一點)。

如果你喜歡用代碼構造你的單元格,你可以使用相同的邏輯。

0

一種方式將是對的UITableViewCell的backgroundView設置爲在方法含有對灰色背景

1

此白盒的的UIImageView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    ... 

    cell.backgroundColor = [UIColor whiteColor]; 

    // This will create a line of 3 pixels that will be separating the cells 
    UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,3)]; 
    separator.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separator]; 

    // and if you want the border do left and right add: 
    UIView *separatorRx = [[UIView alloc] initWithFrame:CGRectMake(318,0,2,cell.frame.size.height)]; 
    separatorRx.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separatorRx]; 

    UIView *separatorSx = [[UIView alloc] initWithFrame:CGRectMake(0,0,2,cell.frame.size.height)]; 
    separatorSx.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separatorSx]; 

    return cell; 

} 

enter image description here

0

你必須創建一個UITableViewCell的子類。在你自己的子類中,你可以創造你夢寐以求的一切!因此,您需要將UIViewwhiteColor背景和邊距作爲您自定義UITableViewCell的子視圖添加。

0

UITableView中沒有填充選項。您可以在您的UITableViewCell中添加UIView,其中包含所有單元格子視圖,並更改它的框架以在單元格中創建填充權限。

建議您使用UICollectionView來代替,您可以使用佈局輕鬆設置單元格之間的空間。如果單元格小於實際的集合視圖,則它會自動居中。

相關問題