美文网首页
UITableViewCell选中效果颜色设置

UITableViewCell选中效果颜色设置

作者: 蓝色的雪啦 | 来源:发表于2016-12-09 17:20 被阅读186次

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

相关文章

网友评论

      本文标题:UITableViewCell选中效果颜色设置

      本文链接:https://www.haomeiwen.com/subject/dhxymttx.html