I'm trying to create a Grid layout that shows some pictures. Now I'm using a FlowLayout and I create my CollectionView like this:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
Gop *g = _images[(NSUInteger) indexPath.row];
@weakify(self);
[[self.imageService fetchImageFromURLAsString:g.imageUrl] subscribeNext:^(UIImage *img) {
@strongify(self);
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[cell.contentView addSubview:imageView];
} error:^(NSError *error) {
[_snackbar displaySnackbarWithMsg:NSLocalizedString(@"snackbar.error.no.network", nil)];
} completed:^{
DDLogDebug(@"Fetched image");
}];
return cell;
}
#pragma mark – UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(100,100);
}
Don't worry for the reactive cocoa part, it just retrieves an image from the internet.
Now the image is 1920 x 1080 but I want a gallery of images of 100 x 100 for example. So I implemented the UICollectionViewDelegateFlowLayout method and created a size off 100x100. Now my image don't show 100 x 100 and my image content isn't visible. I only see some image from the left corner I guess ( of the bigger picture ).
How can I fit my images that they are 100 x 100 and all in line with each other?
Screenshot what I have now:
I hoped on a result something like this:
http://www.appcoda.com/wp-content/uploads/2013/01/RecipePhoto-App-First-Version.jpg