就像在Objective中一样,我们可以获得Collection View Cell的对象,如下所示。有一些Swift的问题
-(void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DatasetCell *datasetCell =
(DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
[datasetCell replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]];
datasetCell.backgroundColor = [UIColor skyBlueColor]; }
答案 0 :(得分:2)
试试这个:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let datasetCell = collectionView(collectionView, cellForItemAtIndexPath: indexPath) as DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()
}