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 하는것도 잊지마세요.
'IT > iOS' 카테고리의 다른 글
[iOS] UIView 부분적으로 라운드 적용하기 (2) | 2015.05.19 |
---|---|
[iOS] 앱평가 하기, 리뷰 남기기는 iRate로 (0) | 2015.03.30 |
iOS8 버그 unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow (0) | 2014.11.06 |
iOS8 푸쉬 등록 에러메세지 (registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later) (0) | 2014.10.02 |
[iOS] Draw line (0) | 2014.08.13 |
[iOS] 원 이미지 만들기 (0) | 2014.08.12 |
UIButton title multi-line (0) | 2014.08.08 |
UILabel text size height (0) | 2014.08.05 |