天天看點

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