1

背景が本棚である UICollectionView に雑誌の表紙のコレクションをレイアウトしようとしています。棚ごとに 2 つの雑誌を配置し、下にスクロールすると残りの雑誌が表示されるようにします。ここに私が持っている私のコードがあります:

-(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:@"icon@2x.png"]];


    //    [titleLabel2 setText:entry.articleTitle];






    return cell;
}

collectionView セルを作成するために XIB を使用しています。

問題が 2 つしかない場合は問題ないように見えますが、問題がどんどん追加されてスクロールしなければならなくなると、かなりずれます。

ここに画像の説明を入力 ここに画像の説明を入力 ここに画像の説明を入力

4

1 に答える 1

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];
于 2013-07-05T18:08:29.943 に答える