2011-01-28 68 views
4

我正在使用帶分組的UITableView。我的第一個小組創建了一個沒有背景色的自定義單元格,並且我還想要移除單元格周圍的邊框。我怎樣才能做到這一點?爲每個部分自定義UITableView部分邊框顏色

對於我的第一個單元格,我想將border/seperator樣式設置爲[UIColor clearColor]。

enter image description here

編輯:蘋果做到這一點在他們的聯繫人應用程序,我想設計類似的東西。

回答

3

我相信蘋果公司在其聯繫方式中使用的是tableView:viewForHeaderInSection:,第0部分,而不是第一部分中的單元格。您仍然可以指定透明背景,並且細條紋將顯示在背後。由於分組表格視圖節標題沒有邊框,邊框將不在此處。

無論是在Interface Builder中構建自定義單元格還是使用代碼,將這些視圖從UITableViewCell遷移到UIView以便與tableView:viewForHeaderInSection:一起使用應該是相當簡單的任務。

我不知道你是否就可以保持詳細標題,比如說,部分1,除非你包含這個詞的標籤,並將其手動添加到部分0頭視圖。

+0

如果您將它更改爲節標題,那麼它將不像以前那樣滾動。即它會粘在屏幕的頂部,而該部分在它下面滾動,這可能是你不想要的。 – noRema 2013-02-19 11:16:11

3

如果我理解你的問題,在cellForRawIndexPath你應該添加 -

if(indexPath.section==0){ 

//set the style you wish to add only to the first section 

} 

好運

編輯

我用這個函數,該函數 -

+(void)setTransparentBgToCell:(UITableViewCell*)cell{ 
     UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)]; 
     backgroundView.backgroundColor = [UIColor clearColor]; 
     cell.backgroundView = backgroundView; 
     [backgroundView release]; 
     cell.selectionStyle=UITableViewCellSelectionStyleNone; 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
} 

shani

+0

是的,但我所能找到的是爲整個tableView設置它:tableView.separatorColor = [UIColor clearColor]; \t \t tableView.separatorStyle = UITableViewCellSeparatorStyleNone; – 2011-01-28 21:03:51

+0

你說得對。我添加了一個函數,我在我的一個應用程序中使用,試試這個.shani – shannoga 2011-01-29 01:07:48

4
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

if(indexPath.section == 0){ 

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 

    } 
} 
相關問題