Adjusting Collections View to ImageView (Width & Height)

Discussion in 'iOS Programming' started by loon3y, Jul 8, 2013.

  1. loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    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:



    [​IMG]
     
  2. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #2
    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
     

Share This Page