2013-07-05 3 views
1

배경이 책꽂이 인 UICollectionView에서 잡지 표지 컬렉션을 레이아웃하려고합니다. 선반 당 2 개의 잡지가 있고 나머지는 스크롤 할 때 보일 수 있기를 바랍니다. 여기에 내 코드가있다 :UICollectionView의 이미지 레이아웃

-(void)viewDidLoad { 

     UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil]; 

    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"]; 
    self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"shelves.png"]]; 
} 
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    return 1; 
    NSLog(@"1"); 
} 
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
     return [_allEntries count]; 
    NSLog(@"2"); 
} 

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 


    RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row]; 


    static NSString *cellIdentifier = @"cvCell"; 

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 

    UIImageView *titleLabel = (UIImageView *)[cell viewWithTag:100]; 
    UILabel *titleLabel2 = (UILabel *)[cell viewWithTag:200]; 

      NSString *thearticleImage = entry.articleImage; 
       [titleLabel setImageWithURL:[NSURL URLWithString:entry.articleImage] placeholderImage:[UIImage imageNamed:@"[email protected]"]]; 


    // [titleLabel2 setText:entry.articleTitle]; 






    return cell; 
} 

나는 collectionView 셀을 만들기 위해 XIB를 사용하고있다.

만이 문제가있는 경우, 잘 보이지만 점점 더 많은 문제가 추가됩니다 당신이 스크롤해야하기 시작, 그들은 아주 하차 :

enter image description here enter image description here enter image description here

답변

0

귀하 셀 사이의 패딩을 사용하여 UICollectionViewCell을 계산하는 것은 잘못된 것일 수 있습니다. 이미지 크기로 재생하거나 프로그래밍 방식으로 셀 크기를 설정할 수 있습니다.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{  
    return CGSizeMake(192.f, 192.f); 
} 

또한 Interface Builder에서 패딩으로 재생할 수도 있습니다.

또한 프로그램이 작업을 수행 할 수 있습니다

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
[flowLayout setItemSize:CGSizeMake(100, 200)]; 
[flowLayout setMinimumInteritemSpacing:10]; 
[flowLayout setMinimumLineSpacing:10]; 
관련 문제