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

时间:2015-12-04 19:48:15

标签: html tvos apple-tv

我想知道如何将某个iframe的网页包装到Apple TV的tvos应用程序中。我能够使用UITextView写出要在tvos应用程序中显示的基本HTML - 具有基本样式的基本div - 但是,我无法弄清楚如何写出iframe。

下面的代码,使用XCode在Objective C中编写,将显示“hello !!!!”在Apple TV模拟器中,但不是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

1 个答案:

答案 0 :(得分:2)

UITextView无法加载iframe。你需要UIWebView来做到这一点,但是TvOS中没有这个API。

HTML显示在你的例子中的原因是因为你可以像你正在做的那样在UITextView中呈现HTML / CSS,但它实际上并没有像在UIWebView中那样被处理,它&# 39; s仅用于样式化内容作为属性文本的替代。

相关问题