iOS集合视图UICollectionViewCell的选种(高亮)效果

来源:互联网 发布:淘宝运费模板如何删除 编辑:程序博客网 时间:2024/05/24 02:15

当我们使用集合视图UICollectionView时,往往需要给UICollectionViewCell的点击事件加一个跟UIButton一样的高亮效果,否则用户会觉得其实自己压根没点中一样,这样无形之中便降低了用户体验,今天我来说说如何给集合视图UICollectionViewCell的选种添加高亮效果。

直接看代码吧:

//当cell高亮时返回是否高亮- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{    return YES;}- (void)collectionView:(UICollectionView *)colView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];    //设置(Highlight)高亮下的颜色    [cell setBackgroundColor:[UIColor colorWithString:@"f2f2f2"]];}- (void)collectionView:(UICollectionView *)colView  didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{    UICollectionViewCell* cell = [colView cellForItemAtIndexPath:indexPath];    //设置(Nomal)正常状态下的颜色    [cell setBackgroundColor:[UIColor whiteColor]];}


1 0
原创粉丝点击