0
A
回答
1
謝謝@Kjuly和@ Selkie的回答。我讓它適用於你們兩個人。
- set
selectedBackgroundView
的backgroundColor first。 - 變化
cell.textLabel.backgroundColor
和cell.contentView.backgroundColor
在didSelectedRowAtIndexPath
。
再次感謝您。
1
如何改變背景顏色的委託方法:
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
2
設置selectedBackgroundView
的顏色,只要你想在您的自定義的tableview細胞是什麼(是的UITableViewCell的子類):
UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];
[selectedBackgroundView release];
,或者你可以在-tableView:cellForRowAtIndexPath:
方法進行設置:
//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...
1
試試這個:
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
3
當所選行
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
}
相關問題
- 1. 更改所選UITableViewCell的邊框顏色
- 2. 如何更改所選UITableViewCell的視圖
- 3. 如何在選擇時將UITableViewCell的顏色更改爲藍色
- 4. 更改選擇的視圖顏色
- 5. 更改UITableViewCell背景顏色時選擇
- 6. 更改自定義視圖的顏色
- 7. 如何更改選定列的顏色?
- 8. 如何更改選定的ListItem顏色
- 9. Swift UITableviewCell顏色更改
- 10. iPhone:選擇時如何更改UITableViewCell中的字體顏色?
- 11. 如何更改UITableViewCell的藍色選擇?
- 12. 如何更改TabLayout選定選項卡的圖標顏色?
- 13. 如何更改未選定的透視標題的顏色?
- 14. 更改視圖顏色基於另一個視圖的顏色
- 15. 如何使用UIActionSheet更改自定義UITableViewCell的顏色?
- 16. 更改選定的文本視圖顏色
- 17. 如何更改列表視圖的特定行顏色
- 18. 如何更改特定視圖上導航欄的顏色
- 19. 如何更改我的圖像選定的背景顏色?
- 20. 更改UITableViewCell中UILabel的文本顏色
- 21. 如何更改回收站視圖中選定項目的文本顏色
- 22. 如何切換UITableViewCell的選擇顏色?
- 23. 如何在運行時更改自定義視圖顏色?
- 24. Ionic2選項卡 - 如何更改選定選項卡的顏色?
- 25. 如何爲ActionbarTab更改選定的選項卡顏色或字體顏色?
- 26. 更改列表視圖行的顏色
- 27. 更改moreNavigationController的顏色配置視圖
- 28. 使用SimpleCursorAdapter.ViewBinder更改視圖的顏色
- 29. 更改視圖顏色的問題
- 30. 更改視圖的背景顏色?
在我看來用戶點擊,選擇2也不是很好的解決方法,雖然它的工作原理。因爲它在選擇時總是會改變單元格的正常背景顏色,而當它被取消選擇時,它需要再次設置爲正常! – Kjuly 2012-07-20 03:59:25