天天看点

iOS UITableViewCell选中后的颜色设置

1.系统默认的颜色设置

//无色
 cell.selectionStyle=UITableViewCellSelectionStyleNone;
 //蓝色,也就是系统默认的颜色
 cell.selectionStyle=UITableViewCellSelectionStyleBlue;
 //灰色
 cell.selectionStyle=UITableViewCellSelectionStyleGrap;
           

2.自定义UITableViewCell选中后的背景颜色和背景图片

UIColor* color=[[UIColor alloc]initWithRed: green: blue: alpha:];//通过RGB来定义颜色
 cell.selectedBackgroundView=[[UIView alloc]initWithFrame:cell.frame]autorelease];
 cell.selectedBackgroundView.backgroundColor=[UIColor   ***]或color;
 
 自定义选中后的背景图片
 cell.selectedBackgroundView=[[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"123.png"]]autorelease];
 设置UITableViewCell中的字体颜色时用
 cell.textLabel.highlightedTextColor=[UIColor **color];
           

3.定义UITableViewCell的样式

不设置accessoryType时是这样的

iOS UITableViewCell选中后的颜色设置

设置accessoryType后是这样的

iOS UITableViewCell选中后的颜色设置

accessoryType有如下几种

typedef enum {
   UITableViewCellAccessoryNone,
   UITableViewCellAccessoryDisclosureIndicator,
   UITableViewCellAccessoryDetailDisclosureButton,
   UITableViewCellAccessoryCheckmark
} UITableViewCellAccessoryType;
           

4.隐藏UITableViewCell的分隔线

[chatTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

   UITableViewCellSeparatorStyle有如下几种 
typedef enum {
   UITableViewCellSeparatorStyleNone,
   UITableViewCellSeparatorStyleSingleLine,
   UITableViewCellSeparatorStyleSingleLineEtched
} UITableViewCellSeparatorStyle;
           

5设置UITableViewCell之间分隔线的颜色

[chatTableViewsetSeparatorColor:[UIColor blueColor]];
           

还有其他颜色可以设置,你们可以自已试试

原文地址:

http://blog.csdn.net/a6472953/article/details/7532212