如何在Apple TV的tvos应用程序中编写HTML iframe

如何在Apple TV的tvos应用程序中编写HTML iframe,html,tvos,apple-tv,Html,Tvos,Apple Tv,我想知道我怎样才能把一个网页用某种iframe包装成一个苹果电视的tvos应用程序。我能够使用UITextView写出基本HTML以显示在tvos应用程序中-带有基本样式的基本div-但是,我不知道如何写出iframe 下面的代码是使用XCode用Objective C编写的,它将在Apple TV模拟器中显示“hello!!!!”,但不会在iframe中显示 下面是我的代码。有什么帮助吗?谢谢 #import "ViewController.h" @interface ViewControl

我想知道我怎样才能把一个网页用某种iframe包装成一个苹果电视的tvos应用程序。我能够使用UITextView写出基本HTML以显示在tvos应用程序中-带有基本样式的基本div-但是,我不知道如何写出iframe

下面的代码是使用XCode用Objective C编写的,它将在Apple TV模拟器中显示“hello!!!!”,但不会在iframe中显示

下面是我的代码。有什么帮助吗?谢谢

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(IBAction)print:(id)sender{

}

- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect textViewFrame = CGRectMake(20.0f, 20.0f, 280.0f, 124.0f);
    UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
    textView.returnKeyType = UIReturnKeyDone;
    [self.view addSubview:textView];

    NSString* staticHTMLContent = @"<div>hello!!!!</div> <iframe     frameborder=""1"" width=""420"" height=""345"" src=""//www.youtube.com/embed/C8kSrkz8Hz8""></iframe>";

    NSAttributedString* myHTMLString = [[NSAttributedString alloc] initWithData:[staticHTMLContent dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType} documentAttributes:nil error:nil];

    [textView setAttributedText:myHTMLString];
}


@end
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
-(iAction)打印:(id)发件人{
}
-(无效)viewDidLoad{
[超级视图下载];
CGRect textViewFrame=CGRectMake(20.0f、20.0f、280.0f、124.0f);
UITextView*textView=[[UITextView alloc]initWithFrame:textViewFrame];
textView.returnKeyType=UIReturnKeyDone;
[self.view addSubview:textView];
NSString*staticHTMLContent=@“你好!!!!”;
NSAttributedString*myHTMLString=[[NSAttributedString alloc]initWithData:[静态HTMLContent数据使用编码:NSUTF8StringEncoding]选项:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}文档属性:nil错误:nil];
[textView setAttributedText:myHTMLString];
}
@结束

UITextView不会加载iframe。您需要UIWebView来实现这一点,但该API在TvOS中不可用

在您的示例中显示HTML的原因是,您可以在UITextView中呈现HTML/CSS,但实际上并不像在UIWebView中那样进行处理,它只是用于将内容样式化,作为属性文本的替代