gpt4 book ai didi

objective-c - 更改 Objective-C 中每个其他单元格的背景颜色

转载 作者:可可西里 更新时间:2023-11-01 17:09:54 24 4
gpt4 key购买 nike

我有一个 uiTableView。我希望每个其他单元格都获得另一种背景颜色。我正在尝试这样。但这是行不通的。有人有线索吗?

 if(indexPath.row % 2 == 0){
cell.backgroundColor = [UIColor whiteColor];
}else{
cell.backgroundColor = [UIColor blueColor];
}

亲切的问候,

史蒂夫

最佳答案

您可以在 tableView:cellForRowAtIndexPath:

中使用: cell.contentView.backgroundColor 而不是 cell.backgroundColor

或者:(来自 Apple 文档)

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.

关于objective-c - 更改 Objective-C 中每个其他单元格的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12686592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com