
- (BOOL )collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void )collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; cell.selectedBackgroundView.backgroundColor = [UIColor purpleColor]; } 这样点选以后颜色没有变化
1 PopeyeLau 2015-09-11 17:08:03 +08:00 应该是在 cellForItemAtIndexPath 方法 设置 cell 的 selectedBackgroundView 跟 backgroundColor 吧. 如果前面没设置, didSelectItemAtIndexPath 里面取 selectedBackgroundView 应该是 nil. |
2 l12ab 2015-09-11 22:13:26 +08:00 我怎么记得默认带选中效果? |
3 kobe1941 2015-09-11 22:55:54 +08:00 一般子类化 cell ,然后自行设置高亮和选中的效果 |
4 strom001 OP ```objc - (void )collectionView:(UICollectionView *)colView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor blueColor]; } - (void )collectionView:(UICollectionView *)colView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = nil; } ``` 这段是 xcode 文档里的 |