UITableView单元格背景颜色 [英] UITableView cell background color

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

问题描述

如何为UITableView
中的单元格设置不同的背景颜色(特别是七个单元格的彩虹颜色)

how to set different background colors for cells in a UITableView (specifically rainbow color for seven cells)

推荐答案

设置 backgroundColor 属性:

cell.backgroundColor = [UIColor redColor];

请注意,必须在 tableView:willDisplayCell:forRowAtIndexPath中设置backgroundColor: 方法(来自 UITableViewCell参考):

Note that the backgroundColor must be set in the tableView:willDisplayCell:forRowAtIndexPath: method (from UITableViewCell reference):


注意:如果要更改单元格的
背景颜色(通过
UIView声明的
backgroundColor属性设置
单元格的背景颜色你必须在
tableView中执行:willDisplayCell:forRowAtIndexPath:
方法委托而不是
tableView:cellForRowAtIndexPath:
数据源。
组样式表视图中单元格的
背景颜色的更改在iOS 3.0中的效果为
,与
以前版本的运行
系统不同。它现在影响
区域内的圆角矩形而不是
区域。

Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.

使用indexPath参数实现彩虹效果。

Use the indexPath parameter to achieve the rainbow effect.

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

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