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.
Asked
Active
Viewed 81 times
-2
-
get image size from server or first download image and find aspect ratio (size) of image – Kumar Mar 10 '17 at 10:18
-
how we will get the image size from server?. How will send the aspect ration to server ? – user1482232 Mar 10 '17 at 10:20
-
I want to make image like mentioned URL https://havecamerawilltravel.com/photographer/instagram-square – user1482232 Mar 10 '17 at 10:26
-
have a look at : http://stackoverflow.com/questions/23760275/dynamic-size-uicollectionview-cell – Ravi Mar 10 '17 at 10:28
2 Answers
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;
}
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

Ravi Vaishnav
- 36
- 6