0

I am generating PDF with image and problem is that

 [imageview.image drawInRect:CGRectMake(0, 0, 100, 100)];

in generated PDF my image got stretched to size we define in CGRectMake so how can my image set to Aspect Fit not UIImageView ?

my size is fixed 100*100 in PDF but image need to aspectFit

Any help ?

Rushi trivedi
  • 737
  • 1
  • 15
  • 37

2 Answers2

0

This is what you need to do. It will maintain the aspect ratio of whatever you want to add in a block.

Calculate the size of the image and then add in the CGRect.

CGRect AVMakeRectWithAspectRatioInsideRect(CGSize aspectRatio, CGRect boundingRect);

For more information check this documentation

ankit
  • 154
  • 1
  • 11
  • tried but when drawinrect with 100*100 image for streched because it is not possible to [imageview drawInRect only [imageview.image drawInRect possible – Rushi trivedi Oct 11 '18 at 12:58
0

you can try to set contentmode of your imageview , where the content of view(image) changes when views bound changes

for ex: imageView.contentMode = UIViewContentModeScaleAspectFit;

Refer: contentmode in apple documentation

Jerry
  • 21
  • 2