最佳答案
我假设您的 cellForItemAtIndexPath
知道如何获取单元格编号(即 1
、2
、3
、图片上的 4
)从 NSIndexPath
传递给该方法。然后,您可以通过获得除以 3 的余数来决定使用什么颜色,如下所示:
// Decode index path into cell number from your picture
int cellNumber = [self getCellNumberFromIndexPath:indexPath];
// Figure out the color
if (cellNumber % 3 == 1) {
// 1, 4, 7, etc
... // Use black color
} else if (cellNumber % 3 == 2) {
// 2, 5, 8, etc
... // Use white color
}
关于ios - 如何识别 UICollectionview 中的特定单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37762155/