1

So I have a UIWebView and there is an image showed inside it. The question is, is there any way for me to get the width, height, origin-x, origin-y of this image? I have added a UITapGestureRecognizer. What I want is that when I tap on the image, it gives me this information. How can I achieve this?

EDIT: Why doesn't this work:

NSString * widthJs = [NSString stringWithFormat:@"document.getElementById('imageid').clientHeight;"
];
    NSString * heightJs = [NSString stringWithFormat:@"document.getElementById('imageid').clientWidth;"
                          ];

    NSString *width = [self stringByEvaluatingJavaScriptFromString:widthJs];
    NSString *height = [self stringByEvaluatingJavaScriptFromString:heightJs];
     NSLog(@"Coor height is %@ with coor width is %@", width, height);
xonegirlz
  • 8,889
  • 19
  • 69
  • 127

1 Answers1

1

You asked two questions.
Q1: how to interact UIWebView with iOS framework?
stringByEvaluatingJavaScriptFromString is a keyword. and you can find many articles about this by google.
Q2: how to get image informations by javascript?
How to get image size (height & width) using javascript?

Community
  • 1
  • 1
xhan
  • 6,057
  • 4
  • 33
  • 47