
UICollectionview cell selection
UICollectionview cell 선택시 효과를 주는 방법입니다.
저는 셀 선택시 테두리에 색을 입히는 방법을 썼습니다.
int selectedCellIndex; 선언
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MiddleCell* cell = (MiddleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MiddleCell" forIndexPath:indexPath];
if (selectedCellIndex == indexPath.row) {
cell.layer.borderWidth = 2.0;
cell.layer.borderColor = [UIColor colorWithRed:0.965 green:0.427 blue:0.196 alpha:1.000].CGColor;
}
else
{
cell.layer.borderWidth = 0.0;
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
selectedCellIndex = (int)indexPath.row;
}
셀 선택 후 collectionview reloadData 하는것도 잊지마세요.