2013-07-17 125 views
1

我有一個UITableView幾個部分的靜態單元格都在我的故事板文件中設置。如何將UITableView中的單元格顏色設置爲透明?

我的問題是:如何設置其中一個單元的顏色是透明的? 我試圖去視察>背景下的單元格,並將其設置爲>清除顏色,但這樣做給單元格一個「清晰」的顏色,但單元格的邊界仍然可見: enter image description here,

有人可以幫我實現這個沒有邊界嗎?謝謝

****編輯****我已經嘗試將alpha級別設置爲0,但這似乎沒有影響。

我也試圖實現以下,但我得到了相同的結果上面的圖片:

_topCell.backgroundColor = [UIColor clearColor]; 

我也試圖實現:

self.tableView.separatorColor = [UIColor clearColor]; 

,並得到以下結果:

enter image description here

請忽略verti校準線將描述中的標題分開,這只是一個帶垂直線圖像的UIImageView

只是爲了給大家一個想法,我這樣做是因爲最終我在尋找一個清晰/乾淨的單元格來添加一些圓形矩形按鈕,例如「文本消息」,「共享聯繫人」&「Add to收藏夾」按鈕,如下圖所示:

enter image description here

+0

這是沒有直接關係,但是從我讀,使用透明色的大大減慢滾動速度。這可能不再是這種情況,但在iOS 5下,表格視圖幾乎不可用。 – dasblinkenlight

+0

@dasblinkenlight我很欣賞這個建議,我會看一看,看看這個卷軸是否明顯放慢了,而不是絕對需要更換,再次感謝! – vzm

+0

你真的應該爲子孫後代清理這個問題。您已經接受了與標題中提出的問題無關的答案。 –

回答

7

在您的視圖控制器:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell.backgroundColor = [UIColor clearColor]; 
    cell.layer.backgroundColor = [UIColor clearColor];//optional 
    cell.backgroundView = nil; 
} 

行評論說:「可選」當你設置與圖案像一個自定義表的背景顏色(如discussed here)時,才需要。

當然,如果你只是想這適用於特定的細胞,你需要把這些語句在if塊。

0
cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.35]; 
+0

其實,我已經嘗試過這一點,但它似乎並沒有在所有影響小區設置alpha爲0,每說@Abdullah Shafique先生 – vzm

+0

@vzm試試這行代碼 –

2

我取得了類似的東西,只是濫用段和段尾。使用章節應該組合在一起行的各組重要(這是單元格樣式「分組」的點)

例如,你可以讓一個枚舉,使他們的軌跡:

enum Sections 
{ 
    SectionName, 
    SectionPhone, 
    SectionAddress, 
    // etc... 
    SectionCount 
}; 

然後,通常使用這些部分:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return SectionCount; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section == SectionName) 
    { 
     return 2; // First name, last name 
    } 
    else if (section == SectionPhone) 
    { 
     return 1; // Just his phone number 
    } 
    else if (section == SectionAddress) 
    { 
     return 4; // Country, State, Street, Number 
    } 
    // etc... 
} 

而且有「動作」,你可以添加相關的特定部分的操作,則只需添加這兩種方法

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    return 52; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    // Only the Address has action buttons, for example 
    if (section != SectionAddress) 
    { 
     return nil; 
    } 

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)]; 

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

    [button1 setTitle:@"Action 1" forState:UIControlStateNormal]; 
    [button2 setTitle:@"Action 2" forState:UIControlStateNormal]; 
    [button3 setTitle:@"Action 3" forState:UIControlStateNormal]; 

    button1.frame = CGRectMake(8, 8, 96, 44); 
    button2.frame = CGRectMake(button1.frame.origin.x + button1.frame.size.width + 8, 8, 96, 44); 
    button3.frame = CGRectMake(button2.frame.origin.x + button1.frame.size.width + 8, 8, 96, 44); 

    [view addSubview:button1]; 
    [view addSubview:button2]; 
    [view addSubview:button3]; 

    return view; 
} 

返回具有獨立按鈕的視圖。

preview

+0

我曾嘗試實施這一併得到一個更好的結果不相當我在找什麼,我已經更新了這個問題來解釋。 @Can – vzm

+0

我更新了我的答案@vzm – Can

+0

有趣的方法,你會介意多解釋一些細節嗎?謝謝@Can – vzm

相關問題