我可以使用突出显示表格视图单元格而没有目标c中的默认蓝色吗?

时间:2022-04-11 09:17:42

I doing a project where i need to use highlighted table view color not default.

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

2 个解决方案

#1


Of course you can.

当然可以。

There are two methods to achieve this:

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

  1. Use UITableViewCell's selectedBackgroundView and selectedTextColor properties
  2. 使用UITableViewCell的selectedBackgroundView和selectedTextColor属性

  3. Subclass UITableViewCell and implement the drawInRect and setSelected:animated: methods
  4. 子类UITableViewCell并实现drawInRect和setSelected:animated:方法

The latter option gives you more flexibility and much better performance, but it might be slightly harder if you haven't used CoreGraphics before.

后一种选择为您提供了更大的灵活性和更好的性能,但如果您以前没有使用过CoreGraphics,可能会稍微困难一些。

UPDATE In response to the OP's comment:

更新回应OP的评论:

Here's how you can use the selectedBackgroundView property:

以下是如何使用selectedBackgroundView属性:

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

I haven't tried this myself, but it should work.

我自己没试过,但它应该有效。

#2


Try referring to this demo - maybe you could have a look at it and get some help.

试着参考这个演示 - 也许你可以看看它并获得一些帮助。

#1


Of course you can.

当然可以。

There are two methods to achieve this:

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

  1. Use UITableViewCell's selectedBackgroundView and selectedTextColor properties
  2. 使用UITableViewCell的selectedBackgroundView和selectedTextColor属性

  3. Subclass UITableViewCell and implement the drawInRect and setSelected:animated: methods
  4. 子类UITableViewCell并实现drawInRect和setSelected:animated:方法

The latter option gives you more flexibility and much better performance, but it might be slightly harder if you haven't used CoreGraphics before.

后一种选择为您提供了更大的灵活性和更好的性能,但如果您以前没有使用过CoreGraphics,可能会稍微困难一些。

UPDATE In response to the OP's comment:

更新回应OP的评论:

Here's how you can use the selectedBackgroundView property:

以下是如何使用selectedBackgroundView属性:

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

I haven't tried this myself, but it should work.

我自己没试过,但它应该有效。

#2


Try referring to this demo - maybe you could have a look at it and get some help.

试着参考这个演示 - 也许你可以看看它并获得一些帮助。