码迷,mamicode.com
首页 > 其他好文 > 详细

自定义UITableViewCell的背景颜色

时间:2015-08-28 15:11:30      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

自定义UITableViewCell的背景颜色,实际上是对cell的contentView的背景颜色进行设置,所以可以有以下方法: 方法一: cell.contentView.backgroundColor = [UIColor redColor]; 方法二: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; bgview.opaque = YES; bgview.backgroundColor = [UIColor orangeColor]; [cell setBackgroundView:bgview]; 以上是自定义cell. contentView的背景颜色或view的方法实现cell的自定义背景色,下面有UITableView的UITableViewDelegate方法,也可以实现此效果。代码如下: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row%2==0) { cell.backgroundColor = [UIColorwhiteColor]; }else { cell.backgroundColor = [UIColorlightGrayColor]; } }

自定义UITableViewCell的背景颜色

标签:

原文地址:http://www.cnblogs.com/QQ765286788/p/4766414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!