我正在尝试在 UIWebView 中显示图像。但我不知道为什么我的图像未在 UIWebVeiw 中显示。这是我的代码。
-(void)pInterest
{
UIImage *myImage;
myImage=imgView.image;
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
webViewController.mypimage = myImage;
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:webViewController animated:YES];
}
现在将图像传递给 WebViewController 我的 WebViewController 代码是,
- (void)viewDidLoad
{
NSData* data = UIImageJPEGRepresentation(mypimage, 1.0f);
[Base64 initialize];
NSString *strEncoded = [Base64 encode:data];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:@"<html> <body>"];
[htmlString appendFormat:@"<p align=\"center\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></p>", buttonUrl];
[htmlString appendFormat:@"<p align=\"center\"><img width=\"400px\" height = \"400px\" src=%@></img></p>", imageUrl];
[htmlString appendFormat:@"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:@"</body> </html>"];
[mywebview setBackgroundColor:[UIColor clearColor]];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[mywebview loadHTMLString:htmlString baseURL:baseURL];
[mywebview setOpaque:NO];
}
当我尝试使用此代码时,它显示以下结果。
任何帮助都会得到帮助。谢谢