我需要将 TableView 的默认蓝色选择更改为某种自定义颜色。有什么办法可以做到这一点吗?帮帮我
最佳答案
最好的方法是这样的:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"myCellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIView *v = [[[UIView alloc] init] autorelease];
v.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = v;
}
// Set up the cell...
cell.textLabel.text = @"foo";
return cell;
}
与您相关的部分是 cell.selectedBackgroundView = v;
指令。
您可以将此处非常基本的 View “v”替换为您喜欢的任何 View 。
关于iphone - 需要更改 TableView 选择的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1485678/