【问题标题】:is it possible to use iframe in UIWebView?是否可以在 UIWebView 中使用 iframe?
【发布时间】:2011-03-02 13:08:55
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c ios uiwebview facebook-iframe


    【解决方案1】:

    是的,这是可能的,我正在使用 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 步:通过调用 viewDidLoad 内的方法 embedYouTube 将 web 视图添加到主视图

    [self embedYouTube];
    

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

    【讨论】:

    • 但是播放的时候会全屏,有什么办法可以直接在webview里面播放吗?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-17
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多