UICollectionViewCell选中高亮状态和UIButton的高亮状态和选中状态
UICollectionViewCell选中高亮状态
//设置点击高亮和非高亮效果! - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; [cell setBackgroundColor:[UIColor lightGrayColor]]; } - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; [cell setBackgroundColor:[UIColor whiteColor]]; }
UIButton的高亮状态
[_backBtn setBackgroundImage:[UIImage imageNamed:@"tijiao_n"] forState:UIControlStateNormal]; [_backBtn setBackgroundImage:[UIImage imageNamed:@"tijiao_c"] forState:UIControlStateHighlighted];
UIButton的选中保持这个状态再点击取消状态
[button setImage:[UIImage imageNamed:@"like"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:@"like"] forState: UIControlStateHighlighted]; [button setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected]; [button setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected | UIControlStateHighlighted];