Search code examples
uiimageviewxcode5cgrectmake

Xcode 5, why isn't the image resizing?


Hello I am trying to resize a UIImage, but even though I'm not getting any errors it is not working.

hers the code of .h file

IBOutlet UIImageView *Fish;

heres the code of .m file

Fish.frame = CGRectMake(0, 0, 300, 293);

What am I doing wrong? Thanks for any help


Solution

  • The image is probably not resizing because you are just resizing the image view. Make sure in your storyboard that you make the image view (Fish), have the move ScaleToFill. I can't do screenshot due to reputation ( sorry :( )

    Alternately, if your goal is not to resize the image view but to resize the image it is holding, you can do this:

    UIImage *image = Fish.image;
    UIImage *image = YourImageView.image;
        UIImage *tempImage = nil;
        CGSize targetSize = CGSizeMake(80,60);
        UIGraphicsBeginImageContext(targetSize);
    
        CGRect thumbnailRect = CGRectMake(0, 0, 0, 0);
        thumbnailRect.origin = CGPointMake(0.0,0.0);
        thumbnailRect.size.width  = targetSize.width;
        thumbnailRect.size.height = targetSize.height;
    
        [image drawInRect:thumbnailRect];
    
        tempImage = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
        YourImageView.image = tempImage;
    

    and you would set thumbnailRect to whatever size you want.

    Hope this helps! Please search Nerdy Lime on the app store to find all of my apps! Thanks!