UIWebview未在iFrame中加载YouTube视频 [英] UIWebview is not loading youtube video in iFrame

查看:145
本文介绍了UIWebview未在iFrame中加载YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将HTML字符串加载到 UIWebView 中。 HTML包含 iframe ,但它没有在webview中加载。

I'm trying to load an HTML string into a UIWebView. The HTML contains an iframe, but it does not load in the 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];
}

这篇关于UIWebview未在iFrame中加载YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆