UITableViewCell选中效果颜色设置

在iOS 开发中我们经常会遇到产品需求要求在用户选择哪一行Cell时,突出它的选中效果,这样的话我们就需要给每一行Cell都设置一个颜色,易于辨别是否选中!iOS中也有系统默认选中颜色设置,但是颜色单调,只有无色,蓝色,灰色,三种颜色设置,如果想要其他的颜色效果,我们自由自定义设置!
1.系统默认的颜色设置

//无色cell.selectionStyle = UITableViewCellSelectionStyleNone;//蓝色cell.selectionStyle = UITableViewCellSelectionStyleBlue;//灰色cell.selectionStyle = UITableViewCellSelectionStyleGray;

2.自定义颜色和背景设置
改变UITableViewCell选中时背景色:

UIColor *color = [[UIColoralloc]initWithRed:0.0green:0.0blue:0.0alpha:1];//通过RGB来定义自己的颜色 cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease]; cell.selectedBackgroundView.backgroundColor = [UIColor color];

3自定义UITableViewCell选中时背景

cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease]; 另外修改字体的颜色 cell.textLabel.highlightedTextColor = [UIColor redColor]; [cell.textLabel setTextColor:color];//设置cell的字体的颜色

4.设置tableViewCell间的分割线的颜色

[LeftTableView setSeparatorColor:[UIColor redColor ]];

5、设置cell中字体的颜色

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if( !indexPath.row ) { cell.textLabel.textColor = [UIColor redColor]; cell.textLabel.highlightedTextColor = [UIColor redColor]; }

文/轻斟浅醉17(简书作者)原文链接:http://www.jianshu.com/p/e0973bf771f4著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容