2013-07-05 5 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; 
} 

Я использую XIB для создания ячейки collectionView.

Когда есть только 2 проблемы, она выглядит хорошо, но, как добавляются все больше и больше вопросов, и вы начинаете иметь для прокрутки, они получают совсем от:

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]; 
Смежные вопросы