0

UICollectionView을 페이지 당 2x3 격자로 배치하려고합니다. 여기에 지금까지 무엇입니까 무엇 : 당신이 볼 수 있듯이2x3 그리드를 생성하기 위해 UICollectionView를 배치하는 문제 iOS

enter image description here

다음 "페이지"내가 원하지 않는 오른쪽에서 엿보는된다. 나는 내 너비가 항상 320pts (iPhone 만)가 될 것이라는 것을 알면 내 셀이 130pts가되도록 할 것이라고 생각했다. width과 15pts가 양쪽에있다. 레이아웃 delegate에 대한

코드 :

- (CGSize)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout*)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 

    return CGSizeMake(130, 130); 
} 

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView 
         layout:(UICollectionViewLayout*)collectionViewLayout 
     insetForSectionAtIndex:(NSInteger)section { 
    return UIEdgeInsetsMake(20.0f, 15.0f, 20.0f, 15.0f); 
} 

또한 cellForItemAtIndexPath :

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
       cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    CustCollectionViewCell *cell = 
     [collectionView dequeueReusableCellWithReuseIdentifier:kReuseID 
              forIndexPath:indexPath]; 

    //Set up list name label 
    cell.LblListName.font = [self getDefaultFontWithSize:15.0f]; 
    cell.LblListName.textColor = fontAndTertiaryColor; 
    cell.LblListName.textAlignment = NSTextAlignmentCenter; 
    cell.LblListName.text = @"Failtron"; 
    //cell.LblListName.adjustsFontSizeToFitWidth = YES; 

    cell.backgroundColor = secondaryColor; 
    cell.parallaxIntensity = kParallaxMotion; 
    [Utilities createViewBorder:cell]; 

    return cell; 
} 
내가 인세 CSSpadding처럼 행동 것이라고 생각

하지만 난 하나와 마크 떨어져있어 믿고, 나는 또한 UIStoryboard에서 내 레이아웃이 흐르도록 설정되어 있음을 알아야합니다. 관련 코드가 누락 되었다면 알려주십시오.이 코드는 UICollectionView의 첫 번째 시도입니다. 나는 이것을 scrollhorizontally으로 원한다.

+0

그래서 collectionview를 가로로 스크롤하려고하지만 다음 페이지를보고 싶지는 않습니다. 그게 맞습니까? – jhilgert00

+0

예, 맞습니다. –

답변

1

좋아, 거기 UICollectionView에 대한 레이아웃을 조작하는 방법의 톤이있다, 그러나 당신이 원하는대로 레이아웃을 조정할 다음 방법을 사용하여 당신은 당신의 .h<UICollectionViewDelegateFlowLayout>를 구현할 수있다 "흐름"을 사용하고 있기 때문에 같은 소리 :

#pragma mark – UICollectionViewDelegateFlowLayout 

- (CGSize)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout*)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 

    // Size of the cell 
    CGSize retval = CGSizeMake(130,130); 
    return retval; 
} 

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView 
         layout:(UICollectionViewLayout*)collectionViewLayout 
     insetForSectionAtIndex:(NSInteger)section { 

    //top, left, bottom, right 
    return UIEdgeInsetsMake(0, 20, 0, 20); 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout *)collectionViewLayout 
      minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { 

    //Minimum spacing between cells 
    CGFloat interimSpacing = 0.0f; 
    return interimSpacing; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout *)collectionViewLayout 
      minimumLineSpacingForSectionAtIndex:(NSInteger)section { 

    // Minimum spacing between lines. In your case, 
     this is the distance between columns 
    // If your scroll direction was vertical, 
     this would be the distance between rows 
    CGFloat lineSpacing = 20.0f; 
    return lineSpacing; 
} 

이 코드에는 원하는 값에 가까운 값이 미리 입력되어 있습니다.

또는 인터페이스 작성기에서 UICollectionView을 선택하고 Size Inspector의 값을 조정하면됩니다. 내 의견으로는 혼란 스럽지만 말입니다.

+0

또한, 을 구현하면, 이전의 서브 클래스이기 때문에'UICollectionViewDelegate>가 필요하지 않습니다. – jhilgert00

+0

그랬어! 도움을 주셔서 감사합니다. 그리고 나는 IB에서 이것을하는 것이 나에게 조금 성가시다는 것에 동의합니다. –

+0

@ jhilgert00 프로토콜이 아니기 때문에 실제로 하위 클래스는 아닙니다. 레이아웃 프로토콜은 또한 콜렉션 뷰 델리 게이션에 "부합"합니다. 서브 클래스는 상당히 다른 것입니다. – Mundi

관련 문제