UICollectionView image on cell memory warning

前端 未结 1 851
你的背包
你的背包 2020-12-22 03:58

im using Xcode 4.6.1, iOS SDK 6.1, ARC and Storyboards, testing device iphone 4S running 6.1.3

I\'m having a little trouble configuring a collection

相关标签:
1条回答
  • 2020-12-22 04:55

    Scale down the image size in the method

    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath
    

    You can use the category for UIImage available here

    Use the method

    - (UIImage *)thumbnailImage:(NSInteger)thumbnailSize
          transparentBorder:(NSUInteger)borderSize
               cornerRadius:(NSUInteger)cornerRadius
       interpolationQuality:(CGInterpolationQuality)quality;
    

    Edit: 1. Include the following files from the url http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/

    • UIImage+Resize.h, UIImage+Resize.m
    • UIImage+RoundedCorner.h, UIImage+RoundedCorner.m
    • UIImage+Alpha.h, UIImage+Alpha.m

    2.Import the UIImage+Resize.h.

    3.Alter your method

    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath
    

    to look like the below

    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"Entra a las celdas");
        static NSString *identificador=@"celdaImagen";
        celdaImagen *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:identificador forIndexPath:indexPath];
        UIImage* image = [UIImage imageWithContentsOfFile:[imagesArray objectAtIndex:indexPath.item]];
    
        NSData *imageData = UIImagePNGRepresentation(image); //png o jpg
        NSLog(@"tamano imagen %i",(imageData.length)/1024);
    
        myCell.imagen.image=[image thumbnailImage:20 // This should the size of the view in collection view. example: myCell width is 20 and height is 20. 
                                transparentBorder:0
                                     cornerRadius:0
                             interpolationQuality:kCGInterpolationMedium];
        return myCell;
    }
    

    hope it helps.

    0 讨论(0)
提交回复
热议问题