ios 是否可以在 UIWebView 中使用 iframe?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5167907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:05:46  来源:igfitidea点击:

is it possible to use iframe in UIWebView?

iphoneobjective-ciosuiwebviewfacebook-iframe

提问by Piscean

i want to add a facebook like button in my app. in developer.facebook.com i couldn't fine anything about that. is it possible to use iframe created by facebook like button in UIWebView? it think if its possible then i can add a UIWebView in my app which use that iframe. thanx. please write some example code.

我想在我的应用程序中添加一个类似 facebook 的按钮。在 developer.facebook.com 中,我对此无能为力。是否可以使用由 facebook 创建的 iframe,例如 UIWebView 中的按钮?它认为如果可能的话,我可以在我的应用程序中添加一个使用该 iframe 的 UIWebView。谢谢。请写一些示例代码。

采纳答案by ios_Hunter

Yes that is possible you can use the iframe in webview. You need to load the webview with the HTML string. You can also find the related code of HTML for iframe if you search over the net. Moreover you can also use javascript, in webview using the method stringByEvaluatingJavaScript: of UIWebview.

是的,您可以在 webview 中使用 iframe。您需要使用 HTML 字符串加载 webview。网上搜索也可以找到iframe的HTML相关代码。此外,您还可以使用 javascript,在 webview 中使用stringByEvaluatingJavaScriptUIWebview的方法:。

回答by Sameera Chathuranga

Yes it is possible, I am using iFrame to load youtube Video inside the app.

是的,这是可能的,我正在使用 iFrame 在应用程序内加载 youtube 视频。

Following simple steps will guide you to achieve it.

遵循简单的步骤将指导您实现它。

Step 1 : Create a UIWebView in xib
Step 2 : Connect it to your ViewController's .h file. (I am referring it as _wevView in my project).
Step 3 : Create a method embedYouTubein your ViewController's .m file.

第 1 步:在 xib 中创建一个 UIWebView
第 2 步:将其连接到您的 ViewController 的 .h 文件。(我在我的项目中将其称为 _wevView)。
第 3 步:embedYouTube在 ViewController 的 .m 文件中创建一个方法。

-(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];

}

Step 4: Add the webview to your main view by by making a call to the method embedYouTubeinside viewDidLoad

第 4 步:通过调用embedYouTube里面的方法将 webview 添加到您的主视图中viewDidLoad

[self embedYouTube];

Step 5: Compile and run the app. You should be able to view the YouTube player embedded in the page.

第 5 步:编译并运行应用程序。您应该能够查看页面中嵌入的 YouTube 播放器。