Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在目标c中,我是否可以使用高亮显示的表格视图单元格而不使用默认的蓝色?_Iphone_Objective C - Fatal编程技术网

Iphone 在目标c中,我是否可以使用高亮显示的表格视图单元格而不使用默认的蓝色?

Iphone 在目标c中,我是否可以使用高亮显示的表格视图单元格而不使用默认的蓝色?,iphone,objective-c,Iphone,Objective C,我正在做一个需要使用高亮显示的表视图颜色而不是默认颜色的项目 当然可以 有两种方法可以实现这一点: 使用UITableViewCell的selectedBackgroundView和selectedTextColor属性 子类化UITableViewCell并实现drawInRect和setSelected:animated:方法 后一个选项为您提供了更大的灵活性和更好的性能,但如果您以前没有使用过CoreGraphics,则可能会稍微困难一些 更新以回应OP的评论: 以下是如何使用select

我正在做一个需要使用高亮显示的表视图颜色而不是默认颜色的项目

当然可以

有两种方法可以实现这一点:

  • 使用
    UITableViewCell
    selectedBackgroundView
    selectedTextColor
    属性
  • 子类化UITableViewCell并实现
    drawInRect
    setSelected:animated:
    方法
  • 后一个选项为您提供了更大的灵活性和更好的性能,但如果您以前没有使用过CoreGraphics,则可能会稍微困难一些

    更新以回应OP的评论:

    以下是如何使用
    selectedBackgroundView
    属性:

    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
    [bgView setBackgroundColor:[UIColor redColor]];
    [cell setSelectedBackgroundView:bgView];
    [bgView release];
    
    我自己也没试过,但应该能用。

    当然可以

    有两种方法可以实现这一点:

  • 使用
    UITableViewCell
    selectedBackgroundView
    selectedTextColor
    属性
  • 子类化UITableViewCell并实现
    drawInRect
    setSelected:animated:
    方法
  • 后一个选项为您提供了更大的灵活性和更好的性能,但如果您以前没有使用过CoreGraphics,则可能会稍微困难一些

    更新以回应OP的评论:

    以下是如何使用
    selectedBackgroundView
    属性:

    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
    [bgView setBackgroundColor:[UIColor redColor]];
    [cell setSelectedBackgroundView:bgView];
    [bgView release];
    

    我自己没有试过,但它应该会起作用。

    试着引用-也许你可以看看它并得到一些帮助。

    试着引用-也许你可以看看它并得到一些帮助。

    你能详细说明第一种方法吗?我尝试了
    cell.selectedBackgroundView.backgroundColor=[UIColor redColor]
    ,但似乎没有任何改变。你能详细介绍一下第一种方法吗?我尝试了
    cell.selectedBackgroundView.backgroundColor=[UIColor redColor]
    ,但似乎没有任何改变。