Ste*_*ann 3 objective-c uitableview ios ios5
我有一个uiTableView.我希望每个其他单元格获得另一种背景颜色.我这样试试.但它不会起作用.有人有线索吗?
if(indexPath.row % 2 == 0){
cell.backgroundColor = [UIColor whiteColor];
}else{
cell.backgroundColor = [UIColor blueColor];
}
Run Code Online (Sandbox Code Playgroud)
亲切的问候,
燕姿
您可以使用:cell.contentView.backgroundColor而不是cell.backgroundColor内部tableView:cellForRowAtIndexPath:
或者:(来自Apple文档)
注意:如果要更改单元格的背景颜色(通过UIView声明的backgroundColor属性设置单元格的背景颜色),则必须在tableView中执行此操作:willDisplayCell:forRowAtIndexPath:委托方法而不是tableView :cellForRowAtIndexPath:数据源.组样式表视图中单元格背景颜色的更改在iOS 3.0中具有与以前版本的操作系统不同的效果.它现在影响圆角矩形内的区域而不是它外面的区域.
| 归档时间: |
|
| 查看次数: |
6444 次 |
| 最近记录: |