我想用this链接张贴在Pinterest的形象,但我改变编码点点根据我自己的要求,这里是我MainClass代码如何在Pinterest上发布图片?
- (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 {
//imageview.image=mypimage;
[super viewDidLoad];
NSString *description = @"Post your description here";
// Generate urls for button and image
NSString *sUrl = [NSString stringWithFormat:@"http://d30t6wl9ttrlhf.cloudfront.net/media/catalog/product/Heros/mypimage"];
// NSLog(@"URL:%@", sUrl);
NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(@"Protected URL:%@", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
NSString *buttonUrl = [NSString stringWithFormat:@"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%@&description=%@\"", protectedUrl, description];
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]];
[mywebview loadHTMLString:htmlString baseURL:nil];
[mywebview setOpaque:NO];
}
当我使用上面的编码我的WebView不显示图像和我的WebView看起来像下面screenshow
当我将相同的图像实例分配给WebViewController中的图像视图时,其工作imageview.image = mypimage;
所以有人可以告诉我为什么我的webveiw不显示图像。谢谢。
我应该说这不是一个合适的按钮url。请务必在实际发布问题之前确保您尝试加载的资源的网址存在。 – 2013-02-01 22:22:26
当我点击pinit按钮,它是在第一张截图上打开第二张截图,这意味着没有关于url.so的问题,唯一的问题是它不能传递我的图像。 – jamil