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];