1. 程式人生 > >iOS UICollectionView 實現多選及取消

iOS UICollectionView 實現多選及取消

1、首先需要實現這個方法

_resourceCollectionView.allowsMultipleSelection = YES;//實現多選必須實現這個方法2、

2、然後實現以下兩個方法即可

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

ResourceCollectionViewCell *cell = (ResourceCollectionViewCell *)[collectionView cellForItemAtIndexPath

:indexPath];

    cell.label.backgroundColor = ColorFrom16(0xFFEFE5);

}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath

{

ResourceCollectionViewCell *cell = (ResourceCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];

    cell.label.backgroundColor = ColorWhite;

}