iphone - 需要更改 TableView 选择的颜色

标签 iphone colors tableview

我需要将 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/

相关文章:

ios - 更新 TableView 单元格数据

ios - 如何在 Swift 中获取选定行的值?

iPhone - 无法安装应用程序

iphone - 从 NSURL 字符串中获取一个特殊的子字符串

emacs - 如何在 Emacs 中突出显示选项卡

matlab - 如何在 MATLAB 中找到三个相互交叉的圆锥体的共同体积?

css - JavaFX TableView 背景图片

iPhone - 将 ePub 文件转换为 iPhone 应用程序

iphone - 无法使用电子邮件 xcode 发送 pdf 文件

android - SupportActionMode 背景颜色与 Material 设计