【问题标题】:Embedding video in UIWebView using iFrame使用 iFrame 在 UIWebView 中嵌入视频
【发布时间】:2017-05-11 12:23:20
【问题描述】:

我正在尝试在 UIWebView 中嵌入 youtube 视频。但是,当我运行应用程序时,页面是空白

这是我嵌入部分的代码。

NSString* tempDetailString = [NSString stringWithFormat:@"<p align=\"center\"> <iframe src=\"%@\" width=\"%lf\" height=\"%lf\" frameborder=\"0\" allowfullscreen></iframe> </p>", videoURL, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT];

变量videoURLDEFAULT_VIDEO_WIDTHDEFAULT_VIDEO_HEIGHT 均已正确定义。

例如,videoURLhttps://www.youtube.com/embed/CchqGSPNvnsDEFAULT_VIDEO_WIDTHDEFAULT_VIDEO_HEIGHT 分别是 365.0270.0

【问题讨论】:

  • UIWebView是如何分帧的?你检查了吗?

标签: html ios iframe youtube uiwebview


【解决方案1】:

给你我对你的问题的测试:

结果:

我的代码:

#import "ViewController.h"

#define DEFAULT_VIDEO_WIDTH 365.0
#define DEFAULT_VIDEO_HEIGHT 270.0


@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *videoURL = @"https://www.youtube.com/embed/CchqGSPNvns";

    NSString* tempDetailString = [NSString stringWithFormat:@"<p align='center'> <iframe src='%@' width='%lf' height='%lf' frameborder='0' allowfullscreen></iframe> </p>", videoURL, DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT];

    [_webView loadHTMLString:tempDetailString baseURL:nil];

}


@end

您可以在您的tempDetailString 中使用' 替换\"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    相关资源
    最近更新 更多