美文网首页
ios 自定义UICollectionView的item高亮背景

ios 自定义UICollectionView的item高亮背景

作者: 缘來諟夢 | 来源:发表于2021-01-15 11:48 被阅读0次
// 高亮时调用
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
}

// 高亮结束调用
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
}

// 是否可以高亮
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

相关文章

网友评论

      本文标题:ios 自定义UICollectionView的item高亮背景

      本文链接:https://www.haomeiwen.com/subject/qliuaktx.html