ios - UIWebview 没有在 iFrame 中加载 youtube 视频

标签 ios objective-c iframe uiwebview

我正在尝试将 HTML 字符串加载到 UIWebView 中。 HTML 包含一个 iframe,但它不会加载到 webview 中。

这是我的代码,

webDescription = [[UIWebView alloc]initWithFrame:CGRectMake(0, 255,self.view.bounds.size.width, 20)];
[[webDescription scrollView] setBounces: NO];
webDescription.delegate = self;
NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
                                   "<head> \n"
                                   "<style type=\"text/css\"> \n"
                                   "body {font-family: \"%@\"; font-size: %@; COLOR:#111111; background-color:transparent; padding:10px 5px 15px 20px;}\n"
                                   "</style> \n"
                                   "</head> \n"
                                   "<body>%@</body> \n"
                                   "</html>", @"MyriadPro-Regular", [NSNumber numberWithInt:12], _group.gro_content];
[webDescription setBackgroundColor:[UIColor clearColor]];
[webDescription setOpaque:NO];
[webDescription loadHTMLString:myDescriptionHTML baseURL:nil];
[scrollView addSubview:webDescription];

我该如何解决这个问题?

最佳答案

试试这段代码,

- (void)embedYouTube:(NSString *)youtubeUrl frame:(CGRect)frame {
    NSString *embedHTML = @"\
                                <html><head>\
                            <style type=\"text/css\">\
                            body {\
                                background-color: transparent;\
                                color: white;\
                            }\
                            </style>\
                            </head><body style=\"margin:0\">\
                            <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                            width=\"%0.0f\" height=\"%0.0f\"></embed>\
                            </body></html>";
    NSString *html = [NSString stringWithFormat:embedHTML, youtubeUrl, frame.size.width, frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    [videoView loadHTMLString:html baseURL:nil];
    [playerview addSubview:videoView];
}

关于ios - UIWebview 没有在 iFrame 中加载 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20371952/

相关文章:

web-applications - Facebook 应用程序、Iframe 的烦恼(URL 问题)

ios - 如何在 iOS 7 中向应用程序添加具有模糊效果的用户背景?

ios - 对使用 UserDefaults 确保删除的项目在 TableView 中保持删除感到困惑

ios - 无法从 json 响应设置 UICollectionView 部分中的项目数

objective-c - 如何记录应用程序 session 持续时间?

javascript - Joomla iFrame 动态高度

javascript - 无法以编程方式使用 Javascript 填充 iframe

ios - 运行 pod install : Invalid attribute name 时出错

ios - 从 SwiftyJSON block 访问值时遇到问题

objective-c - 关联 UIButton