1.系統(tǒng)默認(rèn)的顏色設(shè)置
//無(wú)色
cell.selectionStyle=UITableViewCellSelectionStyleNone;
//藍(lán)色
cell.selectionStyle=UITableViewCellSelectionStyleBlue;
//灰色
cell.selectionStyle=UITableViewCellSelectionStyleGray;
2.自定義顏色和背景設(shè)置
cell.selectedBackgroundView=[[[UIView alloc] initWithFrame:cell.frame] autorelease];
cell.selectedBackgroundView.backgroundColor=[UIColor xxxxxx];
3自定義UITableViewCell選中時(shí)背景
cell.selectedBackgroundView=[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease];
還有字體顏色
cell.textLabel.highlightedTextColor=[UIColor xxxcolor];
[cell.textLabel setTextColor:color];
4.設(shè)置tableViewCell間的分割線(xiàn)的顏色
[theTableView setSeparatorColor:[UIColor xxxx ]];
5.pop返回table時(shí),cell自動(dòng)取消選中狀態(tài)
首先我有一個(gè)UITableViewController,其中每個(gè)UITableViewCell點(diǎn)擊后都會(huì)push另一個(gè)ViewController肩杈,每次點(diǎn)擊Cell的時(shí)候,Cell都會(huì)被選中媒区,當(dāng)從push的ViewController返回的時(shí)候選中的Cell便會(huì)自動(dòng)取消選中。后來(lái)由于某些原因我把這個(gè)UITableViewController改成了UIViewController掸犬,之后就產(chǎn)生了一個(gè)問(wèn)題:每次返回到TableView的時(shí)候袜漩,之前選中的Cell不能自動(dòng)取消選中,經(jīng)過(guò)查找得知:
UITableViewController有一個(gè)clearsSelectionOnViewWillAppear的property湾碎,
而當(dāng)把UITableViewController修改成UIViewController后噪服,這個(gè)屬性自然就不存在了,因此我們必須手動(dòng)添加取消選中的功能胜茧,方法很簡(jiǎn)單粘优,在viewWillAppear方法中加入:
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
6.點(diǎn)擊后,過(guò)段時(shí)間cell自動(dòng)取消選中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
…………
//消除cell選擇痕跡
[self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}
- (void)deselect
{
[self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES];
}