在iPhone上设置表格视图单元格的背景颜色 [英] Setting background color of a table view cell on iPhone

查看:186
本文介绍了在iPhone上设置表格视图单元格的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想达到一种效果,其中表格视图的一个单元格将具有蓝色背景,下一个将具有白色,下一个将再次具有蓝色,然后是白色等等...您能告诉我吗?我怎样才能做到这一点?

I want to achieve the effect where one cell of the table view will have blue background, the next one will have white, the next one will have blue again, and then white and so on... could you let me know how can I do that?

谢谢。

推荐答案

将此方法添加到表视图委托:

Add this method to your table view delegate:

#pragma mark UITableViewDelegate
- (void)tableView: (UITableView*)tableView 
  willDisplayCell: (UITableViewCell*)cell 
forRowAtIndexPath: (NSIndexPath*)indexPath
{
    cell.backgroundColor = indexPath.row % 2 
        ? [UIColor colorWithRed: 0.0 green: 0.0 blue: 1.0 alpha: 1.0] 
        : [UIColor whiteColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}

这篇关于在iPhone上设置表格视图单元格的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆