2011-11-25 69 views
2

是否可以排除UITableViewCell中的某些子視圖突出顯示或更改突出顯示實施?更改UITableViewCell中某些子視圖的突出顯示

我在UITableViewCell上添加了一個橙色的警告標籤,用於某些場合,並且它與單元格的其餘部分正確地突出顯示,這很好。但是,當單元格停止以動畫方式突出顯示時,首先看到警告標籤的背景變爲白色,然後閃爍爲橙色。 我會喜歡它被排除在突出顯示的位置,或者改變它的突出顯示實現,以便正確地回到橙色。

+0

到目前爲止,我已經知道覆蓋的setHighlight:animated:並立即返回,取消突出顯示。但是當我按下單元格時的亮點仍然會變成藍色。 – SpacyRicochet

+0

其他地方也有類似的問題。我在這裏發佈了一個答案http://stackoverflow.com/a/36886209/81388。 – Peymankh

回答

2

如果超級視圖需要高亮顯示視圖,則不會排除視圖高亮顯示。但是,如果您只是停止任何突出顯示行爲或將其更改爲您的規格,則覆蓋它們的setHighlighted:可以得出相同的結果。

0

不能從動畫刪除某些子視圖,但你可以改變一些行爲如下:

從做一個高亮的動畫這樣避免的UITableViewCell:當選擇一個細胞

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

,做背景手動更改這樣的例子:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    [cell setBackgroundColor:[UIColor purpleColor]]; 

    [UIView animateWithDuration:0.5f animations:^{ 
      [cell setBackgroundColor:[UIColor clearColor]]; 
    }]; 

} 

我做了一個簡單的UITableView和它工作,因爲我需要的。

1

在iOS 6中,可以使用兩種方法在UITableViewDelegate定製突出的電池,並且還子視圖:

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setBackgroundColor:[UIColor lightGrayColor]]; 
} 

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [UIView animateWithDuration:0.5f animations:^{ 
     [cell setBackgroundColor:[UIColor whiteColor]]; 
    }]; 
} 

我沒有顯示的代碼更改子視圖。

但是,您可以採用與您爲每個單元格配置的方式類似的方式,使用單元格viewWithTag訪問子視圖,然後更改背景或任何其他屬性。