1.系統(tǒng)默認(rèn)的顏色設(shè)置
//無色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//藍(lán)色
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//灰色
cell.selectionStyle = UITableViewCellSelectionStyleGray;
2.自定義顏色和背景設(shè)置
改變UITableViewCell選中時背景色:
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];
3.自定義UITableViewCell選中時背景
cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease];
還有字體顏色
cell.textLabel.highlightedTextColor = [UIColor xxxcolor];? [cell.textLabel setTextColor;
4.設(shè)置tableViewCell間的分割線的顏色
[theTableView setSeparatorColor:[UIColor xxxx ]];
5.pop返回table時斩芭,cell自動取消選中狀態(tài)
首先我有一個UITableViewController搂赋,其中每個UITableViewCell點(diǎn)擊后都會push另一個ViewController皂吮,每次點(diǎn)擊Cell的時候,Cell都會被選中蒂胞,當(dāng)從push的ViewController返回的時候選中的Cell便會自動取消選中图呢。后來由于某些原因我把這個UITableViewController改成了UIViewController,之后就產(chǎn)生了一個問題:每次返回到TableView的時候骗随,之前選中的Cell不能自動取消選中蛤织,經(jīng)過查找得知:
UITableViewController有一個clearsSelectionOnViewWillAppear的property,
而當(dāng)把UITableViewController修改成UIViewController后鸿染,這個屬性自然就不存在了指蚜,因此我們必須手動添加取消選中的功能,方法很簡單涨椒,在viewWillAppear方法中加入:
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
6.點(diǎn)擊后摊鸡,過段時間cell自動取消選中
- (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];
}
======加載xib自定cell=====
xxxxx *cell = [tableView dequeueReusableCellWithIdentifier:@"xxxxx"];
if(cell == nil){
cell = [[[NSBundle mainBundle] loadNibNamed:@"xxxxx" owner:self options:nil] objectAtIndex:0];
}