【发布时间】:2011-07-31 08:38:08
【问题描述】:
我需要将 UITableView 单元格选择样式从默认的蓝色更改为红色。谁能帮我解决这个问题?
【问题讨论】:
标签: iphone uitableview
我需要将 UITableView 单元格选择样式从默认的蓝色更改为红色。谁能帮我解决这个问题?
【问题讨论】:
标签: iphone uitableview
您可以尝试根据此tutorial 设置单元格的selectedBackgroundView.image。这也让您可以选择创建漂亮的基于渐变的选择图像。
【讨论】:
UIImageView *selectedBackground = [[UIImageView alloc] initWithFrame:self.view.frame];
selectedBackground.backgroundColor = [UIColor redColor];
[cell setSelectedBackgroundView:selectedBackground];
你可以试试这样的
【讨论】:
如果您将 UITableViewCell 子类化,则可以通过覆盖以下方法来修改其突出显示和选定的 UI 行为。
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
例如:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
self.backgroundColor = [UIColor redColor];
} else {
self.backgroundColor = [UIColor blackColor];
}
}
【讨论】:
您不需要图像或子类化单元格。在 tableView:cellForRowAtIndexPath 中创建单元格时,只需执行以下操作:
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColor redColor];
【讨论】: