我想用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