`

tableView 选中时的背景颜色设置

阅读更多
1.系统默认的颜色设置

//无色 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
//蓝色  ,系统默认是蓝色的
cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
//灰色 
cell.selectionStyle = UITableViewCellSelectionStyleGray;

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

//修改背景颜色
UIView *backgroundViews = [[UIView alloc]initWithFrame:cell.frame];
backgroundViews.backgroundColor = [UIColor grayColor];
[cell setSelectedBackgroundView:backgroundViews];

//修改背景图片
[cell setBackgroundView:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg.png"]]];


3 设置UITableViewCell中的字体颜色时用
cell.textLabel.highlightedTextColor=[UIColor redColor];

4.隐藏UITableViewCell的分隔线
    [self.myTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

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

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

[self.myTableViewsetSeparatorColor:[UIColor blueColor]];

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics