I have a UITableView. I would like to know h开发者_运维问答ow I can perform the following 1) how can i set a custom background color for selected Rows when user selects
2) How can i override selectedBackgroundView on the cell with my own custom view
3) how can i set the background color to whatever i want.
can any one help me please.
To do this you can do one of two things.
The first is create a UIView with the background color you want, then set that view as the cells selectedBackgroundView. So
UIView *bgView = [[UIView alloc] init];
[bgView setBackgroundColor:[UIColor greenColor]];
[cell setSelectedBackgroundView:bgView];
[bgView release];
After this your cell will be green when selected. This assumes your table is of the plain style.
The second option is to set the selection style of your cell like so
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Only thing is that will this option you must use one of the UITableViewCellSelectionStyle constants, and their are only three, gray, blue, and clear. :-(
Hope this helps
精彩评论