[objective-c]UIWebViewのhtmlにUIImageをimgタグで表示

UIWebViewのhtmlにUIImageをimgタグで表示

NSData *imageData = UIImagePNGRepresentation(image);
NSString* base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength];
base64 = [base64 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString*js = [NSString stringWithFormat:@"var img=document.createElement('img');img.src='data:image/jpg;base64,%@';document.body.appendChild(img);",base64];
[mainWebView stringByEvaluatingJavaScriptFromString:js];