Search code examples
objective-cxcodeuiimagecgrectmake

How to make UIImage shown as the size of the UIView


UIImage *image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"%f %f %f %f ", (image.size.width/9), (image.size.height/16), (568/image.size.height), (round((568/image.size.height) * image.size.width)));
if((image.size.width/9)<(image.size.height/16)){
    imageLoad.frame = CGRectMake(0, 0, 320, round((320/image.size.height) * image.size.height));
}
else if((image.size.width/9)>(image.size.height/16)){
    imageLoad.frame = CGRectMake(0, 0, round((568/image.size.height) * image.size.width), 568);
}
else{
    imageLoad.frame = CGRectMake(0, 0, round((568/image.size.height) * image.size.width), 568);
}
NSLog(@"%f %f", imageLoad.frame.size.width, imageLoad.frame.size.height);
imageLoad.hidden = NO;
imageLoad.image = image;

I changed the size of the UIImageView *imageLoad using CGRectMake, and I thought UIImage *image will be shown as the size of the UIImageView *imageLoad. However, it didn't work. What should I do?


Solution

  • // this means your image is fit in to your view size
    imageLoad.contentMode = UIViewContentModeScaleAspectFill