我想在我的应用程序中添加一个类似 facebook 的按钮。在 developer.facebook.com 中,我对此无能为力。是否可以在 UIWebView 中使用由 facebook 创建的类似按钮的 iframe?它认为如果可能的话,我可以在我的应用程序中添加一个使用该 iframe 的 UIWebView。谢谢。请写一些示例代码。
问问题
23285 次
2 回答
15
是的,这是可能的,我正在使用 iFrame 在应用程序中加载 youtube 视频。
遵循简单的步骤将指导您实现它。
第 1 步:在 xib 中创建 UIWebView
第 2 步:将其连接到 ViewController 的 .h 文件。(我在我的项目中将其称为 _wevView)。第 3 步:在 ViewController 的 .m 文件中
创建一个方法。embedYouTube
-(void)embedYouTube {
// Read create a NSString object with iframe
NSString *embedHTML = @"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/embed/rOPI5LDo7mg\" frameborder=\"0\" allowfullscreen></iframe>";
// Initialize the html data to webview
[_webView loadHTMLString:embedHTML baseURL:nil];
// Add webview to your main view
[self.view addSubview:_webView];
}
第 4 步:通过调用embedYouTube
里面的方法将 webview 添加到主视图viewDidLoad
[self embedYouTube];
第 5 步:编译并运行应用程序。您应该能够查看嵌入在页面中的 YouTube 播放器。
于 2013-04-10T05:03:41.660 回答
9
是的,您可以在 webview 中使用 iframe。您需要使用 HTML 字符串加载 webview。如果你在网上搜索,你也可以找到 iframe 的 HTML 的相关代码。此外,您还可以在 webview 中使用 javascript,使用stringByEvaluatingJavaScript
UIWebview 的方法:。
于 2011-03-02T13:30:33.837 回答