본문 바로가기
iOS/iOS

UICollectionView

by 패쓰킴 2022. 11. 4.
728x90

원하는 위치로 스크롤 시키기

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:원하는indexnumber inSection:0];
[_myCollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];

만약, 스크롤이 안된다면

'paging Enabled' 가 체크 해제 되어 있는지 확인 해보자.

 

cell size

1. 셀사이즈 값을 임의로 넣어보아 확인

2. +1

3. 셀사이즈 미적용 해보기

4. UI그려지는 순서 확인

    -> 컬렋ㄴ뷰 슈퍼가 그려지는 순서 확인

 

테이블뷰셀 안에 컬렉션뷰셀 넣기

참고 : https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/

 

원하는 셀 선택된 상태로 만들기

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    NSIndexPath *indexPathForFirstRow = [NSIndexPath indexPathForRow:원하는셀자리 inSection:0];
    [self.myCV selectItemAtIndexPath:indexPathForFirstRow animated:NO scrollPosition:UICollectionViewScrollPositionNone];
    [self collectionView:self.myCV didSelectItemAtIndexPath:indexPathForFirstRow];
}

 

section별 간격

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    if (section == 0) {
        return UIEdgeInsetsMake(0, 0, 0, 12);
    } else {
        return UIEdgeInsetsMake(0, 0, 0, 12);
    }
}

참고: https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout/1617718-collectionview?language=objc

728x90

'iOS > iOS' 카테고리의 다른 글

UIView에 shadow 넣기  (0) 2022.11.23
UIBezierPath  (0) 2022.11.08
DateFormatter  (0) 2022.11.03
UIPickerView  (0) 2022.11.02
navigation stack에서 특정 VC 삭제  (0) 2022.11.02

댓글