[英]iOS / iPhone - setting the color of an arbitrary row
我正在嘗試使用以下代碼在UITableView中設置所選行的顏色:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
}
問題是,它正在所有行上設置顏色。 此外,當我選擇特定行時,它會以藍色突出顯示該行。 如何獲得以紅色突出顯示所選行的信息?
對我來說,最簡單的方法是將UITableViewCell
子類化並覆蓋setSelected:
方法(如果需要,其他所有內容都保留相同)
一些來自舊項目的示例代碼:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
UIView *bg = [[UIView alloc] initWithFrame:self.frame];
bg.backgroundColor = [UIColor colorWithRed:.916 green:.9648 blue:.9844 alpha:1.0];
self.selectedBackgroundView = bg;
[bg release];
// Configure the view for the selected state
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.