开发者

How to change the blue selection of a UITableViewCell?

I've tried to overwrite the accessor for -selectedBackgroundView in a custom UITableViewCe开发者_运维百科ll subclass. However, the cell keeps using the default blue selection background when the cell is selected. How to change that?

I'm actually pretty sure that this blue selection thing is the selectedBackgroundView ... what else should be responsible for this blue background which has a light gradient? The strange thing though, is that the contentView is above that, and while it has a backgroundColor other than [UIColor clearColor], this selectedBackgroundView still seems to shine through. Really strange.


You have to just put this code into "cellForRowAtIndexPath"

For disable the cell select:(While Clicking the cell)

cell.selectionStyle = UITableViewCellSelectionStyleNone;

For enable the cell:(While Clicking the cell)

cell.selectionStyle = UITableViewCellSelectionStyleBlue;(By Default)

cell.selectionStyle = UITableViewCellSelectionStyleGray;

If you want to give your custom colour then in cellForRowAtIndexPath"

if (cell==nil)

{  
 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
 UIView *v = [[[UIView alloc] init] autorelease];
    v.backgroundColor = [UIColor redColor];
    cell.selectedBackgroundView = v;
}

All the best.


Sounds like you simply want to add

self.selectionStyle = UITableViewCellSelectionStyleNone;

to your custom class's init. You can also override the setSelected:animated: method if you want to do any heavy duty handling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜