2015-10-02 101 views
2

在tvOS上導航UITableView時,我無法更改白色背景。UITableView:更改所選單元格背景顏色

爲了設計目的,我在整個桌子上編輯了背景/文字顏色,所以白色選定的背景很煩人。

我想:

cell.selectedBackgroundView.backgroundColor = [UIColor blackColor]; 

但它不更新高亮背景顏色。

回答

6

tvOS使用焦點顯示當前選擇的項目。要更改backgroundColor,請覆蓋單元類中的didUpdateFocusInContext()方法。

public override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { 
    context.previouslyFocusedView?.backgroundColor = UIColor.clearColor() 
    context.nextFocusedView?.backgroundColor = UIColor.blackColor() 
} 
+0

謝謝,我只有客觀的C不迅速,沒有細胞類。如果沒有其他解決方案,我將繼承UITableViewCell並覆蓋此方法。 –

+0

與自定義UITableViewCell的客觀C正常工作,謝謝! –

0

你必須創建一個UIView,並設置爲你的cellForRowAtIndexPath你backgroundview

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCell" forIndexPath:indexPath]; 
    UIView *bgColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 405, 60)]; 

    bgColorView.backgroundColor = [UIColor blackColor]; 
    [cell setSelectedBackgroundView:bgColorView]; 
6

你可以簡單地通過使用focusStyle禁用此:

self.focusStyle = UITableViewCellFocusStyle.Custom 

這將禁用白色背景,但也會禁用任何默認縮放動畫。您應該使用自定義UITableViewCellFocusStyle來處理此問題。

相關問題