-2

I am developing the project like Instagram upload the image and display the all feeds in home page.But image not fitting in image view. In Instagram table view cell automatically fit based on image size please provide me suggestions.

user1482232
  • 17
  • 1
  • 6

2 Answers2

1
[_imageView setImage:[ViewController imageWithContentMode:[UIImage imageNamed:@"howwehelp_bg.png"] withScaledSize:_imageView.bounds.size]];

_imageView.contentMode = UIViewContentModeScaleToFill;

+(UIImage *)imageWithContentMode:(UIImage *)image withScaledSize:(CGSize)newSize{

UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);

[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];

UIImage *imageNew = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return imageNew;

}
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
prasad
  • 82
  • 7
0

You can apply this code for fit images.

+(UIImage*)imageWithImage: (UIImage*) sourceImage scaledToWidth: (float) i_width
{
float oldWidth = sourceImage.size.width;
float scaleFactor = i_width / oldWidth;

float newHeight = sourceImage.size.height * scaleFactor;
float newWidth = oldWidth * scaleFactor;

UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight));
[sourceImage drawInRect:CGRectMake(0, 0, newWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
UIGraphicsEndImageContext();
return newImage;

}

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42