0

I am loading an image into an UIWebView with content mode set to aspect fit. I see there is some empty space in the bottom of the UIWebView. Is there a way to find actual image width and height after loading ? I don't see any direct API for this purpose.. I am posting the code which i tried here..

    aWebView = [[UIWebView alloc]initWithFrame:mapRect];
    aWebView.userInteractionEnabled = YES;
    aWebView.backgroundColor = [UIColor clearColor];
    aWebView.opaque = NO;
    aWebView.scalesPageToFit = YES;
    aWebView.delegate = self;
    aWebView.scrollView.contentMode = UIViewContentModeScaleAspectFit;
    aWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:aWebView];

    NSURL  *url = [NSURL URLWithString:urlText];
    NSURLRequest    *urlRequest = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120];
    [aWebView loadRequest:urlRequest];
    aWebView.scrollView.delegate = self;
    aWebView.delegate = self;

Note: The image is loading from remote server. This is a Native iOS application that is targetted for both iOS 7 and iOS 8.

Thanks..

Srivathsa
  • 606
  • 10
  • 34
  • Have a look on this answer, may be it helps - http://stackoverflow.com/questions/26252101/fit-image-of-random-size-into-a-uiwebview-ios/26252838#26252838 – Kampai Dec 23 '14 at 10:24

1 Answers1

0

Here is the solution that iOS provides to find the actual size after rendering the image view in the given rectangle..

Assume origImgSize is actual physical image size and targetImgSize is the rectangular area of UIImageView on the screen..

CGRect sizeBeingScaledTo = AVMakeRectWithAspectRatioInsideRect(origImgSize, CGRectMake(0, 0, targetImgSize.width, targetImgSize.height));

This gives the actual size of the image after rendering using AspectFit mode.

Srivathsa
  • 606
  • 10
  • 34