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著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值