Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
whats the best solution to have my collections view adjust to the size of my image view,

since photos taken in portrait orientation is longer than when taken in landscape, my image view size is going to vary by screen orientation.


like so:



k14f3b.png
 
This is taken from

Ray Wenderlich's Tutorial on UICollectionView

Code:
#pragma mark – UICollectionViewDelegateFlowLayout
 
// 1
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString *searchTerm = self.searches[indexPath.section]; FlickrPhoto *photo =
    self.searchResults[searchTerm][indexPath.row];
    // 2
    CGSize retval = photo.thumbnail.size.width > 0 ? photo.thumbnail.size : CGSizeMake(100, 100);
    retval.height += 35; retval.width += 35; return retval;
}
 
// 3
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(50, 20, 50, 20); 
}

He has custom objects that represent photos and they have a thumbnail property but you should just be able to use the size of your UIImage
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.